public inbox for gdb@sourceware.org
 help / color / mirror / Atom feed
From: Andrew Dinn <adinn@redhat.com>
To: William Adair <will.adair01@gmail.com>
Cc: gdb@sourceware.org
Subject: Re: GDB Incorrectly Reads & Resolves Shared Library Symbols [MinGW-w64]
Date: Wed, 4 Nov 2020 09:39:28 +0000	[thread overview]
Message-ID: <aa5cbdef-a6c9-fc70-abed-0b4fe3bf843f@redhat.com> (raw)
In-Reply-To: <CAHj+M4LeUx2vhtVmv8WWGg8rM=CMAJspK1tRzXCoOEmnA7GDZw@mail.gmail.com>

Hi William,

On 03/11/2020 23:20, William Adair wrote:
> Great feedback. It was a bit tricky to figure out how GDB was executing
> at first in main(), but I realized that backtrace_command_1 was the
> function I'm looking for in the stack.c file. The stack trace eventually
> hits print_frame_info()->print_frame() [which relies on
> find_frame_sal()] -> find_frame_funname -> lookup_minimal_symbol_by_pc()
> -> lookup_minimal_symbol_by_pc_section()
> A few immediate questions come to mind: What is the minimal symbol
> table? How can I verify that PC is pointing to the section that the
> actual symbol being executed resides in? Lastly, there's a comment: This
> code assumes that the minimal symbols are sorted by ascending address
> values. Does this imply that if the actual symbol for the PC has a lower
> address than the PC that the symbol will be wrong? (I wonder if this is
> what is happening in my case...)

Well, as I said "After that all you need to do is familiarize with the
gdb source!" ;-)

I have not looked into shared lib code much but I believe minimal
symbols are used to record details of symbols in those libs for which
gdb does not have (maybe cannot have?) full info.

The type definition is in symtab.h along with related types symbol and
general_symbol_info. Note that symbol and minimal_symbol both (publicly)
inherit common data from general_symbol_info which crops up all over the
code base. n.b. your quickest way to see what is these types are is to
use gdb:

(outer) ptype minimal_symbol
. . .
(outer) ptype symbol
. . .
(outer) ptype general_symbol_info
. . .

The stuff about address ordering may be the issue but it sounds to me
like this is a comment about how gdb expects its data to be organized.
If something is missing/out of order in gdb's data that may be to do
with the order in the shared lib or it may be because gdb has failed to
read or sort something from the lib.

gdb has a host of _debug vars you can set to trace what it is doing as
it executes a program. This command will help you find them

(outer) info var _debug

The debug vars you probably want to set for tracing symtab processing
can be enabled like this

(outer) break main
...
(outer) commands
 > set symbol_lookup_debug = 1
 > set symtab_create_debug
 > end

The above breakpoint with associated commands will set these debug vars
when gdb starts running.

I suggest you also look at the contents of the shared library outside of
gdb using objdump and/or nm. That will tell you what gdb is trying to
process and you may be able to compare it with the debug output to see
whether any symbols is getting lost or discarded.

> Thanks everyone for your time.
You are welcome. Good luck.

regards,


Andrew Dinn
-----------


      reply	other threads:[~2020-11-04  9:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-31 23:26 William Adair
2020-11-01 14:53 ` Hannes Domani
2020-11-01 15:44   ` William Adair
2020-11-01 18:28 ` Andrew Dinn
2020-11-03 23:20   ` William Adair
2020-11-04  9:39     ` Andrew Dinn [this message]

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=aa5cbdef-a6c9-fc70-abed-0b4fe3bf843f@redhat.com \
    --to=adinn@redhat.com \
    --cc=gdb@sourceware.org \
    --cc=will.adair01@gmail.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).