public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [binutils] Problems about utilizing BFD in a symbolic debugger
@ 2022-03-16  7:36 Rui Hong
  2022-03-16 14:00 ` Nick Clifton
  0 siblings, 1 reply; 2+ messages in thread
From: Rui Hong @ 2022-03-16  7:36 UTC (permalink / raw)
  To: binutils

Hi everyone,


Glad to join the binutils community.

I'm using C to make a symbolic debugger inside a software simulator for RISCV/ELF(DWARF) executable and starting to use binutils-bfd to implement features about symbol/DWARF handling.
Using BFD doc/bfd.h, I've found BFD functions like bfd_find_nearest_line, bfd_canonicalize_symtab to implement features on "symbol-->address-->line", such as command 'b main / b func_name', or showing correct file and line after 'b *0x40000040' command.
But I do not find any other BFD functions on "line-->address", to implement command like 'b main.c:14'.
And the symbol table in ELF or what the bfd_canonicalize_symtab returns seems to be a rather simple symbol table with no variable in the source file, which makes it harder to get a variable's location to implement command like 'p var1'(do I really have to parse DWARF manually?)


I really need advice or some code examples anywhere(I'm looking into GDB source code right now, but it's quite complex. Even a rough location of the code would be helpful)


To sum my questions:
1. how can I map file:line to actual address using BFD?

2. how to build a complete symbol table with variables and their locations in it using BFD?
3. how to get the original complete line number table from .debug_line section using BFD?


Any advice, code example or location of code would be helpful!



Kind regards,
Rui

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [binutils] Problems about utilizing BFD in a symbolic debugger
  2022-03-16  7:36 [binutils] Problems about utilizing BFD in a symbolic debugger Rui Hong
@ 2022-03-16 14:00 ` Nick Clifton
  0 siblings, 0 replies; 2+ messages in thread
From: Nick Clifton @ 2022-03-16 14:00 UTC (permalink / raw)
  To: Rui Hong, binutils

Hi Rui,

> Glad to join the binutils community.

And it is very nice to have you join us.

> Using BFD doc/bfd.h, I've found BFD functions like bfd_find_nearest_line, bfd_canonicalize_symtab to implement features on "symbol-->address-->line", such as command 'b main / b func_name', or showing correct file and line after 'b *0x40000040' command.
> But I do not find any other BFD functions on "line-->address", to implement command like 'b main.c:14'.

There aren't any!  The BFD library does not have code to implement
source line to address mapping.  It only handles the other way around
(is address to source line).  So unfortunately you are going to need
to delve into the GDB code to solve this problem.


> And the symbol table in ELF or what the bfd_canonicalize_symtab returns seems to be a rather simple symbol table with no variable in the source file,

True - and again this is because the BFD library does not implement
this kind of mapping, so there is no need to contain this information
in the symbol table.


Cheers
   Nick


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-03-16 14:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-16  7:36 [binutils] Problems about utilizing BFD in a symbolic debugger Rui Hong
2022-03-16 14:00 ` Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).