From: Raphael Zulliger <zulliger@indel.ch>
To: Pedro Alves <palves@redhat.com>
Cc: gdb@sourceware.org
Subject: Re: Ensure correct symbol-file when attaching to a (remote) process
Date: Tue, 29 Jan 2013 03:51:00 -0000 [thread overview]
Message-ID: <51074733.5030906@indel.ch> (raw)
In-Reply-To: <51073F73.5000905@indel.ch>
On 01/29/2013 04:18 AM, Raphael Zulliger wrote:
> I agree.
> (--build-id is a very interesting feature which I was not aware of.
> Thanks for that hint Jan)
>
> In our scenario, our GDB stub could get that build-id from the running
> target: Our embedded systems provides a variable read/write mechanism
> accessible by the stub. Moreover, the embedded system could be made
> aware of the address of the build-id by introducing variables around
> the .note.gnu.build-id section in the linker script.
>
Here's the solution we came up with. Unfortunately, the solution is not
very GDB-like mainly because the lack of time to create high quality GDB
patches. But at least I want to share our (low-end) solution with you.
(Note: I'm definitely not saying that this is the ideal solution! It's
just good enough for our use cases.)
I post this message because of two purposes:
1. As a reference if someone is searching the web
2. To check if someone comes up with a better solution for reading the
build-id out from an elf file
Here's what we've done in order to read the build-id from within our
C/C++ code of our embedded software:
- We pass "-Wl,--build-id" to the linker invocation
- We extended the linker script by:
.note : {
PROVIDE (__NOTE_BUILDID_BEGIN__ = .);
*(.note.gnu.build-id)
PROVIDE (__NOTE_BUILDID_END__ = .);
} > ram
- In the C/C++ code we have something like this:
extern unsigned int __NOTE_BUILDID_BEGIN__;
extern unsigned int __NOTE_BUILDID_END__;
With these two variables at hand, we are able to propagate the build-id
to our GDB-stub by our own "PC to embedded system communication".
- On the GDB side, we hacked some python code to read the build-id out
from the ELF file:
def GetBuildId():
BuildId = ""
# we only ever have 1 ELF file (or 0 in case of a user error):
for file in gdb.objfiles():
cmd = 'objdump -s -j .note ' + file.filename
p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = p.stdout.read()
for line in output.splitlines():
if len(line) > 0 and line[0] == ' ':
for entry in line.split()[1:5]:
BuildId = BuildId + entry
return BuildId
This is definitely no high-end code, but it does its job. Among others,
It's potentially unstable if objdump changes it's output format... I
searched the web for a better way of getting the content of a certain
section out from an object file, but couldn't find a solution. If
someone knows about a GDB/Python interface for doing so, I would
definitely like to hear about it!
The build-id read out from the ELF file will then be sent to our GDB
stub in a non-GDB way (again some kind of home-made communication, which
we'd already in use). Our GDB stub finally compares the build-id read
from the ELF file with the one read from the embedded system and can
compare them for equality.
Raphael
next prev parent reply other threads:[~2013-01-29 3:51 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-21 6:05 Raphael Zulliger
2012-12-21 16:11 ` Jan Kratochvil
2012-12-21 18:17 ` John Gilmore
2013-01-02 17:57 ` Pedro Alves
2013-01-12 10:59 ` Martin Runge
[not found] ` <50EA78FB.3040609@indel.ch>
2013-01-14 18:57 ` Pedro Alves
2013-01-29 3:18 ` Raphael Zulliger
2013-01-29 3:51 ` Raphael Zulliger [this message]
2013-02-06 18:47 ` Tom Tromey
2012-12-21 21:12 ` Aleksandar Ristovski
2012-12-22 0:38 ` John Gilmore
2012-12-22 2:54 ` Aleksandar Ristovski
2012-12-24 20:02 ` Aleksandar Ristovski
2012-12-26 0:47 ` John Gilmore
2012-12-27 20:13 ` Aleksandar Ristovski
2013-01-29 3:18 ` Raphael Zulliger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=51074733.5030906@indel.ch \
--to=zulliger@indel.ch \
--cc=gdb@sourceware.org \
--cc=palves@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox