From patchwork Fri Feb 2 22:04:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Namhyung Kim X-Patchwork-Id: 196044 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:9bc1:b0:106:209c:c626 with SMTP id op1csp723904dyc; Fri, 2 Feb 2024 14:06:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IG8So8M8id+zdltAraZkJvZgj4qNgFQTIbs77OZrxcqD4BTi/wt0QSBnInG0jtwPIwKzb3q X-Received: by 2002:a17:90a:c684:b0:28e:20d5:a047 with SMTP id n4-20020a17090ac68400b0028e20d5a047mr6689470pjt.27.1706911603117; Fri, 02 Feb 2024 14:06:43 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706911603; cv=pass; d=google.com; s=arc-20160816; b=ypdJy50MkAiX3ZNHjQHeg3DBqLscy8CswGzsjsQ2LA+xmz7VaURrfVPSidrtY3QTvM TolAXyc3O2pE9uvqbn0HlTCs86BbpiqSimZG9FkJlcNoc+Tg4kDN80X/KW+2PeFGlRzs 2f+JA7Iq1zdWIL0Y4z+qcSOgldDrJd2s7/LpdcZTFfDUe+ezCeROIJzOy6JbrTFJDOl3 k4LMdE30F5rTXRIon/OHhV1dEeIBmA+UcYXeXfsHlEv78oP5RLRVUieGAyOr8q40Twv+ Xp48nmoTWzSXsvoFO/rASx2IJ0J7ITKS68mS1aomvoRrPWkyT34LMJ7gXefqZmREHDi7 2nuQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=vOc2Z8JyMWK1Cos1JZ+vw5yBKHBtj+bfr6QqbvgGh24=; fh=hciVlrIpZng8ZH56LuNKBzZCwMRhTxchalCyg/wl3HA=; b=T7xYqTzCdg6VEv4fMFwZWuGwAbkZ+a9TwEVHydFhfNDW8qs8zn4HrUZAp//gQ+dy7+ PDYm2r6XQYQhx7Qhsr4AIIzU9Gf+YrqoO4CQUbffHaQ5ccjuPIe5knxkAEQiQ3fm1qF3 +q/YO3yr/Bmp44bb/2zULx0IoxxqKRfH5cgK5iUkhj5FhrQDdXqHi5uiyzk1S5YPZf9Z klHSHvw1oIE4jruiD+H84yaZI1V54vOEvMSLUYElKtTv3DJMFu9NG09FZLpSOMsX8gcN CAys0XCnpk/BgiZr+VbtQ+Snb7LrwWsAGqRo+iDnz3D0JJXTXBDlUmi2LtEP9NARVWAP 93Iw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=m77Rje8K; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50637-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50637-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCUwLp48F2Z/9X/b7D317TEJEpmxw1OXmaCyy97p2A7axlzcDda55og94NffrbJvOLUADnvqfvgIEMgxvVxKfGypPyygtQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id mh4-20020a17090b4ac400b00296563fbb75si547016pjb.95.2024.02.02.14.06.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 14:06:43 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50637-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=m77Rje8K; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50637-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50637-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id DB2EA28AFDF for ; Fri, 2 Feb 2024 22:06:42 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 51A9612D76C; Fri, 2 Feb 2024 22:05:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="m77Rje8K" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5EE19126F05; Fri, 2 Feb 2024 22:05:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706911504; cv=none; b=AEf1MDc50sIOPZOTXzmW/z3RoCEw+3QUJ8XkRoc9RSe8od5lyjc2rBYHFjbWJyjeW57GiFa/Qm8w40VmS0nPYmRicyH/KXVRAJbWWLAG6LNyGPCHtKJ8IkS48RjGXlO8PgpLyXDAiSaGnTehnslUAzyi3AHiy0SA5+wFUqESUww= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706911504; c=relaxed/simple; bh=ksRwB6y7Bf3D1VViK194iwXHp5tebaWmPZdpxqK0sY0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TnA+i7v3d3liwQtiQbnX2FuNxv3XX+hkxS+AorjE3vfrYxZfFHW614gjn+rw2D7ntfVaHMEOP5QcfjbGVuz2jB9MTV+WsDXUEjwzNc5nUOHadzcA1/rSOS8KWE0HyHb29DsCQsL6RXYibpSXv9yFTLJGLTE5ORCORC41xrwTEzA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=m77Rje8K; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id B86C7C43142; Fri, 2 Feb 2024 22:05:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706911504; bh=ksRwB6y7Bf3D1VViK194iwXHp5tebaWmPZdpxqK0sY0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m77Rje8KR9qi8D7/IwR6G3a4rHlf/J2LNxrkGo9chaQfeUpCtzwJCtvn2yEtaELOR bPS5LmLOZlDx3zlMgBjlypofa0Av7AgggOIMMEYWCI9fEsu7vSpl2r8xY3zcohzotp Jwir98s5VsJsH9Y5CbUem2Ye+RenIHOZDeK+HevXhlTta9PchwxswwTv/w1RAXO4eX QPb0eL+G+aoJ6wQ5xEADdI3PXuLlIn77WFMMCqqgoB1txsrQ3/i+qa4LwzVnV9qzPw jxLWHtmv0kU2eQnID/E4vs9JnoJ1QnmzjGIgA3giByztmpgvXLS46P1QrZGYS3JgND Y9jq+KcezyAmQ== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , 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 04/14] perf map: Add map__objdump_2rip() Date: Fri, 2 Feb 2024 14:04:49 -0800 Message-ID: <20240202220459.527138-5-namhyung@kernel.org> X-Mailer: git-send-email 2.43.0.594.gd9cf4e227d-goog In-Reply-To: <20240202220459.527138-1-namhyung@kernel.org> References: <20240202220459.527138-1-namhyung@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789826540855746179 X-GMAIL-MSGID: 1789826540855746179 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 54c67cb7ecef..66542864b7b5 100644 --- a/tools/perf/util/map.c +++ b/tools/perf/util/map.c @@ -594,6 +594,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 49756716cb13..65e2609fa1b1 100644 --- a/tools/perf/util/map.h +++ b/tools/perf/util/map.h @@ -132,6 +132,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;