[PATCH] Fix infinite recursion bug at get_msymbol_address.

Ali Tamur via gdb-patches gdb-patches@sourceware.org
Thu Nov 7 04:05:00 GMT 2019


The patch 4b610737f0 seems to have introduced the possibility of infinite
recursion. I have encountered the problem while debugging a failing in-house
test. I am sorry, it is fairly difficult to reduce the test case (and I don't
understand most of what is going on) but the stack trace shows a call to
objfpy_add_separate_debug_file, which eventually causes
lookup_minimal_symbol_by_pc_name to be invoked, which calls get_msymbol_address.
Somehow lookup_minimal_symbol_linkage finds the same symbol and the function
calls itself with the same parameters. I don't know whether this should be
classified as 'it should never happen', but this simple patch makes the test
pass and should be harmless, I think.

gdb/ChangeLog

	* symtab.c (get_msymbol_address): Guard against infinite recursion.
---
 gdb/symtab.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/gdb/symtab.c b/gdb/symtab.c
index 2c934b9c22..b231cc6e84 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -6328,7 +6328,7 @@ get_msymbol_address (struct objfile *objf, const struct minimal_symbol *minsym)
 	{
 	  bound_minimal_symbol found
 	    = lookup_minimal_symbol_linkage (linkage_name, objfile);
-	  if (found.minsym != nullptr)
+	  if (found.minsym != nullptr && found.minsym != minsym)
 	    return BMSYMBOL_VALUE_ADDRESS (found);
 	}
     }
-- 
2.24.0.rc1.363.gb1bccd3e3d-goog



More information about the Gdb-patches mailing list