* [PATCH] gdb: detect main function even when there's no matching msymbol
@ 2020-10-08 15:08 Andrew Burgess
2020-10-09 18:33 ` Tom Tromey
0 siblings, 1 reply; 3+ messages in thread
From: Andrew Burgess @ 2020-10-08 15:08 UTC (permalink / raw)
To: gdb-patches
Currently, GDB will only stop the backtrace at the main function if
there is a minimal symbol with the matching name. In Fortran programs
compiled with gfortran this is not the case. The main function is
present in the DWARF, and as marked as DW_AT_main_subprogram, but
there's no minimal symbol.
This commit extends `inside_main_func` to check the full symbols if no
matching minimal symbol is found.
There's an updated test case that covers this change.
gdb/ChangeLog:
* frame.c (inside_main_func): Check full symbols as well as
minimal symbols.
gdb/testsuite/ChangeLog:
* gdb.fortran/mixed-lang-stack.exp (run_tests): Update expected
output of backtrace.
---
gdb/ChangeLog | 5 ++++
gdb/frame.c | 30 ++++++++++++++-----
gdb/testsuite/ChangeLog | 5 ++++
.../gdb.fortran/mixed-lang-stack.exp | 3 +-
4 files changed, 33 insertions(+), 10 deletions(-)
diff --git a/gdb/frame.c b/gdb/frame.c
index 5ae8611a8e6..b4af734c2ee 100644
--- a/gdb/frame.c
+++ b/gdb/frame.c
@@ -2295,19 +2295,33 @@ inside_main_func (frame_info *this_frame)
if (symfile_objfile == nullptr)
return false;
+ CORE_ADDR sym_addr;
+ const char *name = main_name ();
bound_minimal_symbol msymbol
- = lookup_minimal_symbol (main_name (), NULL, symfile_objfile);
+ = lookup_minimal_symbol (name, NULL, symfile_objfile);
if (msymbol.minsym == nullptr)
- return false;
+ {
+ /* In some language (for example Fortran) there will be no minimal
+ symbol with the name of the main function. In this case we should
+ search the full symbols to see if we can find a match. */
+ struct block_symbol bs = lookup_symbol (name, NULL, VAR_DOMAIN, 0);
+ if (bs.symbol == nullptr)
+ return false;
+
+ const struct block *block = SYMBOL_BLOCK_VALUE (bs.symbol);
+ gdb_assert (block != nullptr);
+ sym_addr = BLOCK_START (block);
+ }
+ else
+ sym_addr = BMSYMBOL_VALUE_ADDRESS (msymbol);
- /* Make certain that the code, and not descriptor, address is
- returned. */
- CORE_ADDR maddr
+ /* Convert any function descriptor addresses into the actual function
+ code address. */
+ sym_addr
= gdbarch_convert_from_func_ptr_addr (get_frame_arch (this_frame),
- BMSYMBOL_VALUE_ADDRESS (msymbol),
- current_top_target ());
+ sym_addr, current_top_target ());
- return maddr == get_frame_func (this_frame);
+ return sym_addr == get_frame_func (this_frame);
}
/* Test whether THIS_FRAME is inside the process entry point function. */
diff --git a/gdb/testsuite/gdb.fortran/mixed-lang-stack.exp b/gdb/testsuite/gdb.fortran/mixed-lang-stack.exp
index edf2508537d..8d1f2bc0123 100644
--- a/gdb/testsuite/gdb.fortran/mixed-lang-stack.exp
+++ b/gdb/testsuite/gdb.fortran/mixed-lang-stack.exp
@@ -73,8 +73,7 @@ proc run_tests { lang } {
"#6\\s+$hex in mixed_func_1c \\(\[^\r\n\]+\\) at \[^\r\n\]+" \
"#7\\s+$hex in mixed_func_1b \\($1b_args\\) at \[^\r\n\]+" \
"#8\\s+$hex in mixed_func_1a \\(\\) at \[^\r\n\]+" \
- "#9\\s+$hex in mixed_stack_main \\(\\) at \[^\r\n\]+" \
- "#10\\s+$hex in main \\(\[^\r\n\]+\\) at .*" ]
+ "#9\\s+$hex in mixed_stack_main \\(\\) at \[^\r\n\]+" ]
gdb_test "bt -frame-arguments all" $bt_stack
# Check the language for frame #0.
--
2.25.4
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gdb: detect main function even when there's no matching msymbol
2020-10-08 15:08 [PATCH] gdb: detect main function even when there's no matching msymbol Andrew Burgess
@ 2020-10-09 18:33 ` Tom Tromey
2020-10-11 17:45 ` Andrew Burgess
0 siblings, 1 reply; 3+ messages in thread
From: Tom Tromey @ 2020-10-09 18:33 UTC (permalink / raw)
To: Andrew Burgess; +Cc: gdb-patches
>>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:
Andrew> Currently, GDB will only stop the backtrace at the main function if
Andrew> there is a minimal symbol with the matching name. In Fortran programs
Andrew> compiled with gfortran this is not the case. The main function is
Andrew> present in the DWARF, and as marked as DW_AT_main_subprogram, but
Andrew> there's no minimal symbol.
Andrew> This commit extends `inside_main_func` to check the full symbols if no
Andrew> matching minimal symbol is found.
Andrew> There's an updated test case that covers this change.
Andrew> gdb/ChangeLog:
Andrew> * frame.c (inside_main_func): Check full symbols as well as
Andrew> minimal symbols.
This looks good to me. Thank you.
Tom
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gdb: detect main function even when there's no matching msymbol
2020-10-09 18:33 ` Tom Tromey
@ 2020-10-11 17:45 ` Andrew Burgess
0 siblings, 0 replies; 3+ messages in thread
From: Andrew Burgess @ 2020-10-11 17:45 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
* Tom Tromey <tom@tromey.com> [2020-10-09 12:33:53 -0600]:
> >>>>> "Andrew" == Andrew Burgess <andrew.burgess@embecosm.com> writes:
>
> Andrew> Currently, GDB will only stop the backtrace at the main function if
> Andrew> there is a minimal symbol with the matching name. In Fortran programs
> Andrew> compiled with gfortran this is not the case. The main function is
> Andrew> present in the DWARF, and as marked as DW_AT_main_subprogram, but
> Andrew> there's no minimal symbol.
>
> Andrew> This commit extends `inside_main_func` to check the full symbols if no
> Andrew> matching minimal symbol is found.
>
> Andrew> There's an updated test case that covers this change.
>
> Andrew> gdb/ChangeLog:
>
> Andrew> * frame.c (inside_main_func): Check full symbols as well as
> Andrew> minimal symbols.
>
> This looks good to me. Thank you.
Thanks, I pushed this.
Andrew
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-10-11 17:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-08 15:08 [PATCH] gdb: detect main function even when there's no matching msymbol Andrew Burgess
2020-10-09 18:33 ` Tom Tromey
2020-10-11 17:45 ` Andrew Burgess
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).