From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754065AbcHWQTh (ORCPT ); Tue, 23 Aug 2016 12:19:37 -0400 Received: from mail-db5eur01on0110.outbound.protection.outlook.com ([104.47.2.110]:64824 "EHLO EUR01-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752690AbcHWQTE (ORCPT ); Tue, 23 Aug 2016 12:19:04 -0400 Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=matija.glavinic-pecotic.ext@nokia.com; Subject: Re: [PATCH RFC RESEND] Perf: lookup dwarf unwind stack info in debug file pointed by .gnu_debuglink To: Jiri Olsa References: <2d72fb64-9b9c-7aa1-5ac5-ac710ec5a900@nokia.com> <20160822151919.GA614@krava> <20160823112204.GC6486@krava> <69a799bb-1c54-928e-f58b-fdc8bb3fac0c@nokia.com> CC: , , Namhyung Kim , Masami Hiramatsu From: Matija Glavinic Pecotic Message-ID: <83fbb2b5-df77-220f-7157-6675560f7e72@nokia.com> Date: Tue, 23 Aug 2016 18:18:10 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.1.0 MIME-Version: 1.0 In-Reply-To: <69a799bb-1c54-928e-f58b-fdc8bb3fac0c@nokia.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [88.207.42.27] X-ClientProxiedBy: AM3PR02CA0017.eurprd02.prod.outlook.com (10.242.240.17) To DB6PR0701MB2165.eurprd07.prod.outlook.com (10.168.58.20) X-MS-Office365-Filtering-Correlation-Id: 89305af8-01d7-4c32-ad22-08d3cb7114a1 X-Microsoft-Exchange-Diagnostics: 1;DB6PR0701MB2165;2:9QvEXlmNOukSWQxYPvshmiJq6w4l/GZGtB2NSWIQN8VFBfmFwU1D0cnBgnhelcW21dky2iaW2GGb5mSGQvRCj+NhTcFB8D1PKfVJrywpDUP3u0ZEP6Gs7guD90ILziFATm8UW1pooxaAwCNPOToA5hJ01FD4kq1LOiLZwvjj5kjFkdrouc4wwSoCJ5bhJRHr;3:laWH49EybMt15+hAjZSYEwcaUrczlNRrIs1pA4Qo6kqhSxd26ToVReJ8NZnqqQc8jGAevPVeO2gdzBx7bS/9o6YwUE9FujHAzN/rwNK/JZcaObZGIyrjvFaptEnhkwP1;25:JmyCKQYavMCCRGTH1roWUuZzntFuIcZfPJJextTBPXkHC42/yGHfN2nQHnyO+Ssqjfo+eYMKzTtC1flHb7FoXDufgL6fL3MajfnVMNEHWvy/m8QsAyBmeMJMZ9vXobfRh0c2UgTX8HGR4CziJRRPXn4hqtqopHRLXamL5iRPngDQVuiCySKKdF/N2VrkrYu9BxPsb492892hmoEqFw4pvhdnkOuwAHH3auDnrSnC3qm4RYJg1z8DJYtfwibECMjYOuBuWII9ma2T47L5IXVGK2hdsFy7aNPW6ypS+wR7x2AbsTyoMYx7UV87lkpRRigmqOCb6SCS+SYRIxh7kmY9XtHN3dz1e5XDgFrssM3IYxPPgtbPJnZXvSj7l8lBQvJxbqFVrMmuLd57xtpdp673+g4ISYRqs3T1Gft78CpzxaY= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DB6PR0701MB2165; X-Microsoft-Exchange-Diagnostics: 1;DB6PR0701MB2165;31:WTtBZ/Wk1f5a4fVx6RpNbmjAWtqQYd2JRuBjoQcV1+lmkpU6YGSnQ2nU29rNlXXWNeZ4YPTrs2vhrIuDBcRMUeTiE26MUfpcfpoK7zu0LMLASxRv3AM233QkpMTQcwsrCGi9p4P7hqyvad+EJr9k+V1Izx05QDFX+qxtNTJJtVHkN0qzjSsP4OhQ8tH1Zh7SKBkt284DMp4ywgqnVFDlnG76uSr3r8TERYJVW/xleEU=;20:A+77/VPTFJon4qxLnOSQ7D2EZz7xCq7HBIViNhrFc8GHfm5rBNsnteDKGCsuFP4q266qXc0L8WbA/5L4zG4r/F5Mkmf3/qKAXC4VzY41o1S3iomZ6MZHAbAX0jKK3TSJw0P4TsnNXY8d3J/BhbhiSVgYF4bPorsOCLxk5jY8iIRGaM5mcydwn6MLazG9eQ6WJP8jgfxyGy5imDsaS/DLqpKYGy5YqU++0OvrHZAqW6Iy+D3T+iU6MV0pA0UbKZnRYuwdKrkgg8m8+jLvEejEkFsVE5/wY0H+Pf343w/5UsPiQtApritSheK/mLdE9h12l+mu/yFmDRNCaFx3vn22Ezeo+xHRbsjZfCaIsSbaeqJ9iC9ghW+SzBvIZLIt9ZljU3lFMoVk+4XhAK19KaWPpLmyMSHV0J1pwvCkS+2p/7Yf/LpfeImI2Fi2zJkcyEG540n1+ffNw1iGv1C1n4afE60chMn80XrW9NoneqOHxw7cTzO5G1kz8igqV+n152Wz X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(6040176)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6055026);SRVR:DB6PR0701MB2165;BCL:0;PCL:0;RULEID:;SRVR:DB6PR0701MB2165; X-Microsoft-Exchange-Diagnostics: 1;DB6PR0701MB2165;4:ZGFNP3pS4ddoaznFToVPXtTBYGDUhy25tpgswOtHvHoqu7Efj8jD7rbqNcSi4jPfWSUyjQjJRsbfqlPnKoX3fGYC5BbpLMjOUtZE9RiiDBiM9zDZldZOR2BUAJa8K3m8CSXeurEMDmErDre6x2sOXDhUAYsCiElKgNJU8Vz5VPl9wgP6THQOlzTFHBzDYnMy56mYWXPYEW7LBCisb7gSvUxqdh0gLjGixHMVOdfboe8UBSviF2zW0AcMNScMZSxW4UNXE8L02WCG15Ry/fjiiyf96jkyeJHWXAkAGnsfIVyhYJ2oC7pmdt9BsBumSyWXdk2IGDfdWI6Ye620ho+f4gLxi585F8rUb7M5cFL2W7teLxXNqgD6WJH4sinZP68wcZIO0EmuH2L8Fw/FYDsSYg== X-Forefront-PRVS: 004395A01C X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10019020)(4630300001)(6049001)(6009001)(7916002)(52054003)(199003)(189002)(24454002)(575784001)(31696002)(86362001)(586003)(15975445007)(76176999)(36756003)(47776003)(66066001)(6116002)(105586002)(3846002)(7846002)(50986999)(19580395003)(101416001)(54356999)(106356001)(23746002)(33646002)(4326007)(68736007)(305945005)(110136002)(42186005)(2906002)(31686004)(117156001)(230700001)(64126003)(83506001)(2950100001)(4001350100001)(93886004)(97736004)(7736002)(8676002)(189998001)(50466002)(92566002)(77096005)(5660300001)(81166006)(81156014)(142923001)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DB6PR0701MB2165;H:[192.168.0.12];FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: =?Windows-1252?Q?1;DB6PR0701MB2165;23:Ex03bTDp28MzvJpjQcnN4uiThEiA8VMzCki?= =?Windows-1252?Q?pIDTk15mohMp5Lk5lSmxK9YZSM60zLWFQUIivW9LYiLbZU2+Sl9O5sOL?= =?Windows-1252?Q?s7E11HU/3ILF79uu+wjxpWI9BN98bMAvGJ0xO8lHt1mfGKownJOG62Lp?= =?Windows-1252?Q?9x5kL2E1bp2qYRov1cvZMuO6WrIdifmgPYpDyqg7IFu2k6PJzGMaf1Qx?= =?Windows-1252?Q?zxwqAHdLqpt3XFVklTDBSg8yo3GAhpgSXzmRBIVSA1htyLyMX68Oexk6?= =?Windows-1252?Q?jf7/MR3bORCHXXvKqwQpUWtp6iCS2kx7yRxQAFq6falCQO4B/8HGEZ6F?= =?Windows-1252?Q?ttmBTiX698AdQ34ZCyGo28T94JO9DfDX/SC9fYKNGWZIKKjxUr0Q7Eiw?= =?Windows-1252?Q?lFW66Ria0p98ectwWzywRmTRVR9I7J1y776D+ygJ94TpMwANxeFo4F/f?= =?Windows-1252?Q?dNHjgVkU2b0Bj7r6FHUrRmziubfeKOtq4UGxLiDUW6zjg9GlCD1Nc7p6?= =?Windows-1252?Q?/fF5va4yFha0CC4K47DETkPyOIqNWEoq65M2iHS+rXtIyu6MQ+DF3sw+?= =?Windows-1252?Q?r2vSKYKEcYah+9YsHpG2dRRoc3E5+xkxvXi+zg2asT9aufeqWIvDVo90?= =?Windows-1252?Q?+5Qj38a7K2sdhCzQ2pvY5dOOUA0faiUgaKeSLOBrOzL/f9JaAxFucWuB?= =?Windows-1252?Q?mGut8Ea3zlDXdkW/1cd6QnzdqeNtGGNufkoo8Rbq1F3itet30RPKTvhj?= =?Windows-1252?Q?SaPuWiA2dll61qxF8qJ04VoKgNf/VuA4B715B9JyjFCYErCTx5WDDVct?= =?Windows-1252?Q?i966xazslLjRFo8ASOQmc62/xJ3TR5zdwdoKeweFJIn5DQ3MQ7UE1Kvn?= =?Windows-1252?Q?MtwEiFoCG433Keyy9vzbxhDM1PGsg5I+w9pDqrnr+/r7usbclUc1viO/?= =?Windows-1252?Q?EACAnFA8FbfboDzx5cy0cJ4jiN4Zn39acrQaMj1hChh1g4TVRP4Xp8zf?= =?Windows-1252?Q?lA5FNh77Yeu2xmSwGb7KPmofYsY5k/dFrF+jcqEhh/iJN3ZPoA57tDGw?= =?Windows-1252?Q?bzwQM2+N/0xbUtLNpjOXl7eCWD72r3AXq3/+Cq1mphOH/YNgcKmPeToc?= =?Windows-1252?Q?yhzVBT3bwFRrwIgemfdKCr81LvW8AWswtkgvOqlwc8hk1fFw1yv8IvX9?= =?Windows-1252?Q?WG0Wg00js+BH9IJ7WrShsQhRS75uAqRvNzgeLFum5xxoRvLuKXhj37q1?= =?Windows-1252?Q?BaIjg6JT/ECUYQt9oNBfyCryV9xdqpfnBzuMCdYZILYNX8N7N76VIz++?= =?Windows-1252?Q?NFsPFOA8vKiyoqKfc4Z8NfUIm2OfyGp043QZa5Qe7aIsKtGgnpTuvlH9?= =?Windows-1252?Q?GR88qH8riarTRn1PT5d/uNSOZYq0zIcBSjek88ZZZbqtNUXcz53slOAz?= =?Windows-1252?Q?cuYqYmqKYkTAykN4D1zzr?= X-Microsoft-Exchange-Diagnostics: 1;DB6PR0701MB2165;6:114rlpDLC396i9Aqv1KDz18Yb6ZQsjjoyKR5CI4ZFbWJ0FGjL4GU6a7PEDmc16fBadV2+X8RvwoC80jHNWmVsp/92QWDcmPhHQsGvQRJaxHMETmESN0ACm7/hJjuZ1p3jydL6QFh+buzXNOjoM3UFXLVCsh8PxqQUkeSyOHfs9FZunKfA7va1nMGFBKTAXjUvav3UPVmJAyX9tFwI2/mmfQNfffHso1Pd6OpmMCIHTO14jjlSsgWMXtUdZpSfTsGafgXvi02GOeXtUmHBBHTJl8esFS/onz1jHkTdubcxA/auEB8baujciBO3SsCqWMZGTbVE8YDlLdw5VObq9AA+g==;5:mrU0gZRk4DBRjHy6yKI5ljDaarbdxkGteIE6vlNuyjJBdptzGHa5Q9yuTQhl0RQfSNlg466CKbUWEZ+j7LZAuvHtvvCFuKL+bdzP416Zt7y9JZIGKh/9GZLm1zpwsV4/OAfYIq+WhjJrmPCoFZYiMA==;24:W7sT3ozPZMROwYEZw4bgFOf140KcsLXd0O3jit+G878Sj1q1+vLdaZCz4cxUvxMwEDqYm4/ZboKwGpW0mTZ/StUv0jBFhjIP/oMEHX9euyc=;7:ISBVdrE45N4Np5Uy/n+/3xH5o9z+VXrQR/skajtQYlAetvYhCbw14iJ+OBNi4xsEOLn4rPO5d4bJlNtXtZiByZNkzEUsSebwuDlIstb+aajtUieJekslViFd8k64RZsuwOAIwjgxihlUaL+QssQRYSWxRQgArw+aMvsJoEbUF25heHunycE7rqUoK5xcpHICPjkHWoBclkz57A4SnqdslDEzTLCSDYsnMZ2J524U2527AnNh9lghJ/9s7V26wrQP SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nokia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Aug 2016 16:18:12.3061 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB6PR0701MB2165 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 23/08/16 14:33, Matija Glavinic Pecotic wrote: > On 23/08/16 13:22, Jiri Olsa wrote: >> On Tue, Aug 23, 2016 at 07:09:18AM +0200, Matija Glavinic Pecotic wrote: >>> On 22/08/16 17:19, Jiri Olsa wrote: >>>> should you also set following? >>>> >>>> *offset = ofs >>>> dso->debug_frame_offset = ofs; >>>> >>>> I guess if we found the debuglink section with file having .debug_frame >>>> section, we want to use it for this dso from now on.. >>> >>> I omitted this at first as I was thinking whether it is correct to do so. For >>> our case, stripped dso, symbols in debug file, we are marking offset in other >>> file, and not *this* dso. But I agree to you now, I have checked, and debug >>> frame offset is not used anywhere, so it is a future problem. Someone might >>> be surprised though that offset is marked, but for the other file. >>> >>>> I'd think let's have read_unwind_spec_debug_frame to find .debug_frame >>>> and provide that info under dso object for subsequent reads >>> >>> Yes, that sounds. >>> >>>> so in case we find debuglink-ed file, it has precedence over the file >>>> we found symtab in? assuming thats what dso->symsrc_filename is.. >>> >>> Thanks for pointing that one out, I haven't seen before we could use it. >>> It was introduced with 0058aef65eda9c9dde8253af702d542ba7eef697 and it is >>> aimed to keep name of the file with debug symbols, similar as needed here. >>> >>> I would then propose something like this below. This significantly changes >>> dso__read_binary_type_filename, but I would say it wasn't proper before and >>> it is not in sync with the rest of the cases in it. Idea of this function is >>> to provide path to dso, and DSO_BINARY_TYPE__DEBUGLINK implies one location, >>> which is not entirely correct. >>> >>> gdb and objcopy docs give points what debug link might be, and where debug >>> file might reside. Debug link might be absolute path, or just name, in which >>> case debug file should be looked up in several places. Here is what gdb does: >>> >>> So, for example, suppose you ask gdb to debug /usr/bin/ls, which has a debug >>> link that specifies the file ls.debug, and a build ID whose value in hex is >>> abcdef1234. If the list of the global debug directories includes >>> /usr/lib/debug, then gdb will look for the following debug information files, >>> in the indicated order: >>> >>> - /usr/lib/debug/.build-id/ab/cdef1234.debug >>> - /usr/bin/ls.debug >>> - /usr/bin/.debug/ls.debug >>> - /usr/lib/debug/usr/bin/ls.debug. >>> >>> https://sourceware.org/gdb/onlinedocs/gdb/Separate-Debug-Files.html >>> https://sourceware.org/binutils/docs/binutils/objcopy.html >>> >>> Could you please tell me what are your thoughts on this kind of approach? >>> >>> --- >>> tools/perf/util/dso.c | 40 ++++++++++++++++++++++++++++++++ >>> tools/perf/util/unwind-libunwind-local.c | 28 +++++++++++++++++++++- >>> 2 files changed, 67 insertions(+), 1 deletion(-) >>> >>> diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c >>> index 774f6ec..ecc859e 100644 >>> --- a/tools/perf/util/dso.c >>> +++ b/tools/perf/util/dso.c >>> @@ -46,11 +46,14 @@ int dso__read_binary_type_filename(const struct dso *dso, >>> switch (type) { >>> case DSO_BINARY_TYPE__DEBUGLINK: { >>> char *debuglink; >>> + char *dir; >>> + char symfile[PATH_MAX]; >>> >>> len = __symbol__join_symfs(filename, size, dso->long_name); >>> debuglink = filename + len; >>> while (debuglink != filename && *debuglink != '/') >>> debuglink--; >>> + dir = debuglink; >>> if (*debuglink == '/') >>> debuglink++; >>> >>> @@ -60,8 +63,45 @@ int dso__read_binary_type_filename(const struct dso *dso, >>> >>> ret = filename__read_debuglink(filename, debuglink, >>> size - (debuglink - filename)); >>> + if (ret) >>> + break; >>> + >>> + /* Check predefined locations where debug file might reside: >>> + * - if debuglink is absolute path, check only that one >>> + * If debuglink provides just name: >>> + * - in the same directory as dso >>> + * - in the .debug subdirectory of dso directory >>> + * - in the /usr/lib/debug/[path to dso directory] >>> + * */ >>> + if (*debuglink == '/') { >>> + ret = is_regular_file(debuglink); >>> + break; >>> + } >>> + >>> + snprintf(symfile, PATH_MAX, "%s/%s", dir, debuglink); >>> + ret = is_regular_file(symfile); >>> + if(!ret) { >>> + strncpy(debuglink, symfile, size); >>> + break; >>> + } >>> + >>> + snprintf(symfile, PATH_MAX, "%s/.debug/%s", dir, debuglink); >>> + ret = is_regular_file(symfile); >>> + if(!ret) { >>> + strncpy(debuglink, symfile, size); >>> + break; >>> + } >>> + >>> + snprintf(symfile, PATH_MAX, "/usr/bin/debug/%s/%s", dir, debuglink); >>> + ret = is_regular_file(symfile); >>> + if(!ret) { >>> + strncpy(debuglink, symfile, size); >>> + break; >>> + } >>> + >>> } >>> break; >>> + >>> case DSO_BINARY_TYPE__BUILD_ID_CACHE: >>> if (dso__build_id_filename(dso, filename, size) == NULL) >>> ret = -1; >>> diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unwind-libunwind-local.c >>> index 97c0f8f..a1d3c93 100644 >>> --- a/tools/perf/util/unwind-libunwind-local.c >>> +++ b/tools/perf/util/unwind-libunwind-local.c >>> @@ -35,6 +35,7 @@ >>> #include "util.h" >>> #include "debug.h" >>> #include "asm/bug.h" >>> +#include "dso.h" >>> >>> extern int >>> UNW_OBJ(dwarf_search_unwind_table) (unw_addr_space_t as, >>> @@ -296,6 +297,8 @@ static int read_unwind_spec_debug_frame(struct dso *dso, >>> { >>> int fd; >>> u64 ofs = dso->data.debug_frame_offset; >>> + char *debuglink = malloc(PATH_MAX); >>> + int ret = 0; >>> >>> if (ofs == 0) { >>> fd = dso__data_get_fd(dso, machine); >>> @@ -304,8 +307,31 @@ static int read_unwind_spec_debug_frame(struct dso *dso, >>> >>> /* Check the .debug_frame section for unwinding info */ >>> ofs = elf_section_offset(fd, ".debug_frame"); >>> - dso->data.debug_frame_offset = ofs; >>> dso__data_put_fd(dso); >>> + >>> + if (!ofs) { >>> + /* If not found, try to lookup in debuglink */ >>> + ret = dso__read_binary_type_filename( >>> + dso, DSO_BINARY_TYPE__DEBUGLINK, >>> + machine->root_dir, debuglink, PATH_MAX); >>> + if (!ret) { >>> + fd = open(debuglink, O_RDONLY); >>> + if (fd < 0) >>> + return -EINVAL; >>> + >>> + ofs = elf_section_offset(fd, ".debug_frame"); >>> + close(fd); >>> + >>> + if (ofs) { >>> + dso->symsrc_filename = debuglink; >> >> symsrc_filename is initialized with file that has symtab, >> which I'm not sure is guaranteed in here as well.. >> >> Namhyung, Massami? > > Yes, I see it. This file could also be debuglink, but that is not guaranteed. > > I would propose to look in symsrc_filename for .debug_frame. If its not there, > we could still take a look into debuglink as a last resort. Something like this. This also expands dso__read_binary_type_filename to return actual path to debuglink, and not just name provided there, which is imho how it should behave: --- tools/perf/util/dso.c | 60 ++++++++++++++++++++++++++------ tools/perf/util/unwind-libunwind-local.c | 47 +++++++++++++++++++++++-- 2 files changed, 94 insertions(+), 13 deletions(-) diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c index 774f6ec..486470f 100644 --- a/tools/perf/util/dso.c +++ b/tools/perf/util/dso.c @@ -44,24 +44,62 @@ int dso__read_binary_type_filename(const struct dso *dso, size_t len; switch (type) { - case DSO_BINARY_TYPE__DEBUGLINK: { - char *debuglink; + case DSO_BINARY_TYPE__DEBUGLINK: + { + const char *last_slash; + char dso_dir[PATH_MAX]; + char symfile[PATH_MAX]; len = __symbol__join_symfs(filename, size, dso->long_name); - debuglink = filename + len; - while (debuglink != filename && *debuglink != '/') - debuglink--; - if (*debuglink == '/') - debuglink++; + last_slash = filename + len; + while (last_slash != filename && *last_slash != '/') + last_slash--; - ret = -1; - if (!is_regular_file(filename)) + strncpy(dso_dir, filename, last_slash - filename); + dso_dir[last_slash-filename] = '\0'; + + if (!is_regular_file(filename)) { + ret = -1; break; + } - ret = filename__read_debuglink(filename, debuglink, - size - (debuglink - filename)); + ret = filename__read_debuglink(filename, symfile, PATH_MAX); + if (ret) + break; + + /* Check predefined locations where debug file might reside: + * - if debuglink is absolute path, check only that one + * If debuglink provides name w/o path, look for debug file: + * - in the same directory as dso + * - in the .debug subdirectory of dso directory + * - in the /usr/lib/debug/[dso directory] + * */ + ret = 0; + if (symfile[0] == '/') { + if (!is_regular_file(symfile)) + ret = -1; + else + strncpy(filename, symfile, size); + break; } + + snprintf(filename, size, "%s/%s", dso_dir, symfile); + if(is_regular_file(filename)) + break; + + snprintf(filename, size, "%s/.debug/%s", dso_dir, symfile); + if(is_regular_file(filename)) + break; + + snprintf(filename, size, "/usr/lib/debug/%s/%s", + dso_dir, symfile); + if(is_regular_file(filename)) + break; + + ret = -1; break; + } + case DSO_BINARY_TYPE__BUILD_ID_CACHE: if (dso__build_id_filename(dso, filename, size) == NULL) ret = -1; diff --git a/tools/perf/util/unwind-libunwind-local.c b/tools/perf/util/unwind-libunwind-local.c index 97c0f8f..345541b 100644 --- a/tools/perf/util/unwind-libunwind-local.c +++ b/tools/perf/util/unwind-libunwind-local.c @@ -35,6 +35,7 @@ #include "util.h" #include "debug.h" #include "asm/bug.h" +#include "dso.h" extern int UNW_OBJ(dwarf_search_unwind_table) (unw_addr_space_t as, @@ -297,15 +298,57 @@ static int read_unwind_spec_debug_frame(struct dso *dso, int fd; u64 ofs = dso->data.debug_frame_offset; + /* debug_frame can reside in: + * - dso + * - debug pointed by symsrc_filename + * - gnu_debuglink, which doesnt necessary + * has to be pointed by symsrc_filename + * */ if (ofs == 0) { fd = dso__data_get_fd(dso, machine); if (fd < 0) return -EINVAL; - /* Check the .debug_frame section for unwinding info */ ofs = elf_section_offset(fd, ".debug_frame"); - dso->data.debug_frame_offset = ofs; dso__data_put_fd(dso); + + if (!ofs) { + fd = open(dso->symsrc_filename, O_RDONLY); + if (fd >= 0) { + ofs = elf_section_offset(fd, ".debug_frame"); + close(fd); + } + } + + if (!ofs) { + char *debuglink = malloc(PATH_MAX); + int ret = 0; + + ret = dso__read_binary_type_filename( + dso, DSO_BINARY_TYPE__DEBUGLINK, + machine->root_dir, debuglink, PATH_MAX); + if (!ret) { + fd = open(debuglink, O_RDONLY); + if (fd >= 0) { + ofs = elf_section_offset(fd, + ".debug_frame"); + close(fd); + } + } + if (ofs) { + if (dso->symsrc_filename != NULL) { + pr_warning( + "%s:overwrite symsrc(%s,%s)\n", + __func__, + dso->symsrc_filename, + debuglink); + free(dso->symsrc_filename); + } + dso->symsrc_filename = debuglink; + } + } + + dso->data.debug_frame_offset = ofs; } *offset = ofs; -- 2.1.4 > What I wonder, would it be fine in such a case to store debuglink to symsrc, if > its already set? Though, this case is somewhat unlikely, but not entirely impossible > > Thanks, > > Matija > >> thanks, >> jirka >> >>> + } >>> + } >>> + } >>> + >>> + pr_debug("%s: dso: %s, ret: %d, debuglink: <%s>\n", >>> + __func__, dso->short_name, ret, debuglink); >>> + >>> + dso->data.debug_frame_offset = ofs; >>> } >>> >>> *offset = ofs; >>> -- >>> 2.1.4 >>> >>>