Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp53730rdg; Wed, 11 Oct 2023 20:57:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHjopeRgQ1dgTf+QtW8ClqPc+N9fJprwtz6knG6Dn3edqpu28gnEZ5nAOK+Ex3pFS1GxpJN X-Received: by 2002:a17:90a:2d82:b0:27d:8d0:713e with SMTP id p2-20020a17090a2d8200b0027d08d0713emr3111760pjd.10.1697083033378; Wed, 11 Oct 2023 20:57:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697083033; cv=none; d=google.com; s=arc-20160816; b=mFY9j8mSV+NphKVCz0UCXc+FpEVHudQI/GWiFhWR0B2mAYGPTAAyqsWndbwYYjVMRC Z1B+W2gDTlidM+ssdHs7pqchqzDlLD948jsyB3uM0YA0erjjxkREdsqeXL2hFhyb8QU0 7ADnnZNliUqetkIPZ324kG+JWUvKLyq/MVLodZcMOndNF0HkJ6hfpNoy5dEt9nd0p5Cd u9El3wY2CDrZDfaq9HCa/1hnYg2JkvYg16BjIOt5h5SafP5utxQ8yPKBHUIYzN+Psv20 aTPseionimvEgJbCKxyVyWNqh8QS8g7Z8UnvHI50/330F6uAyEnanOWoBMvVb8CkJzp3 PjIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature; bh=luk3YMKHP4GBeY8OhFINcROss2mB/uL2Fi/9FHog88E=; fh=7Id7wL2M+oCJXD4imOzx4OKioxBXSOZqypDprm7aO4E=; b=ybs3fhDFxfSB83EC/hrVBa7/gicOwaIRwThMyjbjbhk3Ogg2iNWjtj5oZRbraImlxQ hX8zESEenDH4U3q0OJkQBAt4dHRdNHerjUicggUBzZOz7Ppb9miNcapzi0kwT4JD3j4a 8MyYcXKA37iSfJffvY9cLRNezO00mSjglGJQ8nOUva/bbrrhbiRHMarJgSgGH/6cAkqj y8tR1Jx3vbKdsFT0no414SdEyvSfx/DfAZva44KDyRljPFx7RqAKGGZZysxMFkHakdFN qTlOPA8/un5uUnJOqVPTAGhl21W5iuNjB2sQI0+BWxFtLwHBR2pHOo+mxwaINp5Bxgbf YSeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=JTNPmJY1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id w184-20020a6382c1000000b0056c4189d6cbsi1297610pgd.171.2023.10.11.20.57.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 20:57:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=JTNPmJY1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id C5185802B163; Wed, 11 Oct 2023 20:55:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347085AbjJLDzU (ORCPT + 99 others); Wed, 11 Oct 2023 23:55:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34394 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347104AbjJLDxv (ORCPT ); Wed, 11 Oct 2023 23:53:51 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 419F7170F; Wed, 11 Oct 2023 20:52:04 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1c9b7c234a7so4824385ad.3; Wed, 11 Oct 2023 20:52:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697082723; x=1697687523; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=luk3YMKHP4GBeY8OhFINcROss2mB/uL2Fi/9FHog88E=; b=JTNPmJY17mvmWeekp6EbtnHWVBVsqKijrmriYRPO7H93g6CP46HdEsotwkxTaOTgn4 8nOZ2FEitIOagqfteLV3GG3/th0zm2ZyPPobFJ79tW8vhnkcNkAevkcAkF7wqWd9lUdH fzC9Q1PwAek+3t5Av4A8sjUjkeDBOIBhzndgSMRR2wPL0NUnzgwiWZyDA4x/bejWo4qV 2U/q/CineA/MFqNjLmOR7IUbySKWjGw412JeLsQDlYV7UWtWopeyHFFrInELQDPgwtYV fvIFdHSbj4ZZ9ruNjvumN0R6z4/XZJ4L2eyrWB4rk+KdJ/zlJspUPKTny4pTb3w7F3Me Rwzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697082723; x=1697687523; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=luk3YMKHP4GBeY8OhFINcROss2mB/uL2Fi/9FHog88E=; b=voHCJ+lQZUmZsu/G5ijsbyZHBq3zbCKg2pBRcWtxN/BWeKLQxJFTdOjwJHZC1TcNOt do45x/kz8lJFZWeGFE6KcY9yEEpLZg5Md4J8zSdiUX+EYJkpCIMzG+vaOvk1AFbHoVMO ev54GT4thKlcMgF9mPLcmeDSdQoHUT62y3wXjMJkYVurwD0orzMpw+vKD02fVozM5ekE Hm09vHNbBI9Vv3B8Iebu//xoAFeB3Cw47ylu+9vqXuwgvxK4Orz5W947gFDBD1vZ83bp QZPRuqti8WRBMGJJyV79sM01US/eSOUX3Y6+d58eXkhJPO+rQse9HzJQNWjvRoGyonrN rGXA== X-Gm-Message-State: AOJu0YxGEeuVfUCacbpICNKu7ixvg4SMhOg7Qvd5BUassmo5MjPaWGZn KSZgOGT4VsSH6529BlHKXPfyy59nYO0= X-Received: by 2002:a17:903:228f:b0:1c7:1fbc:b9e7 with SMTP id b15-20020a170903228f00b001c71fbcb9e7mr27350552plh.43.1697082723294; Wed, 11 Oct 2023 20:52:03 -0700 (PDT) Received: from bangji.hsd1.ca.comcast.net ([2601:647:6780:42e0:b1b9:d490:2f5e:be06]) by smtp.gmail.com with ESMTPSA id w8-20020a170902d70800b001bc18e579aesm711374ply.101.2023.10.11.20.52.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 20:52:02 -0700 (PDT) Sender: Namhyung Kim From: Namhyung Kim To: Arnaldo Carvalho de Melo , Jiri Olsa , Peter Zijlstra Cc: Ian Rogers , Adrian Hunter , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Linus Torvalds , Stephane Eranian , Masami Hiramatsu , linux-toolchains@vger.kernel.org, linux-trace-devel@vger.kernel.org Subject: [PATCH 37/48] perf map: Add map__objdump_2rip() Date: Wed, 11 Oct 2023 20:51:00 -0700 Message-ID: <20231012035111.676789-38-namhyung@kernel.org> X-Mailer: git-send-email 2.42.0.655.g421f12c284-goog In-Reply-To: <20231012035111.676789-1-namhyung@kernel.org> References: <20231012035111.676789-1-namhyung@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 11 Oct 2023 20:55:54 -0700 (PDT) Sometimes we want to convert an address in objdump output to map-relative address to match with a sample data. Let's add map__objdump_2rip() for that. Cc: Adrian Hunter Signed-off-by: Namhyung Kim --- tools/perf/util/map.c | 20 ++++++++++++++++++++ tools/perf/util/map.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c index f64b83004421..f25cf664c898 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -595,6 +595,26 @@ u64 map__objdump_2mem(struct map *map, u64 ip) return ip + map__reloc(map); } +u64 map__objdump_2rip(struct map *map, u64 ip) +{ + const struct dso *dso = map__dso(map); + + if (!dso->adjust_symbols) + return ip; + + if (dso->rel) + return ip + map__pgoff(map); + + /* + * kernel modules also have DSO_TYPE_USER in dso->kernel, + * but all kernel modules are ET_REL, so won't get here. + */ + if (dso->kernel == DSO_SPACE__USER) + return ip - dso->text_offset; + + return map__map_ip(map, ip + map__reloc(map)); +} + bool map__contains_symbol(const struct map *map, const struct symbol *sym) { u64 ip = map__unmap_ip(map, sym->start); diff --git a/tools/perf/util/map.h b/tools/perf/util/map.h index 1b53d53adc86..b7bcf0aa3b67 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h @@ -129,6 +129,9 @@ u64 map__rip_2objdump(struct map *map, u64 rip); /* objdump address -> memory address */ u64 map__objdump_2mem(struct map *map, u64 ip); +/* objdump address -> rip */ +u64 map__objdump_2rip(struct map *map, u64 ip); + struct symbol; struct thread; -- 2.42.0.655.g421f12c284-goog