From 697485337184d0f5ed8cdb3ca6d2dae38ec62fd7 Mon Sep 17 00:00:00 2001 From: Lianbo Jiang Date: Mon, 22 Mar 2021 16:30:32 +0800 Subject: [PATCH 10/11] GDB: fix the failure of 'set scope' command Currently some commands such as 'sys' may cause subsequent 'set scope' commands to fail because it may not find the correct symtab associated with PC and SECTION in the find_pc_sect_symtab(), eventually, this will cause the following failure: crash> mod -S 3.10.0-957.el7.x86_64 crash> mod -d dm_service_time crash> mod -sr dm_service_time crash> set scope st_create scope: ffffffffc044d270 (st_create) crash> sys KERNEL: 3.10.0-957.el7.x86_64/vmlinux DUMPFILE: crash/vmcore [PARTIAL DUMP] ... crash> set scope st_create set: gdb cannot find text block for address: st_create To find the correct symtab, let's check whether there is an address mapping to 'block' in the symtab searching loop and the PC is in the range. If the symtab associated with PC is found, and then use it. Signed-off-by: Lianbo Jiang --- gdb-7.6.patch | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/gdb-7.6.patch b/gdb-7.6.patch index f64b55fe547a..2c3ab57375c8 100644 --- a/gdb-7.6.patch +++ b/gdb-7.6.patch @@ -2501,3 +2501,39 @@ diff -up gdb-7.6/opcodes/configure.orig gdb-7.6/opcodes/configure #include "features/aarch64.c" #include "features/aarch64-without-fpu.c" +--- gdb-7.6/gdb/symtab.c.orig ++++ gdb-7.6/gdb/symtab.c +@@ -2080,7 +2080,7 @@ find_pc_sect_symtab (CORE_ADDR pc, struct obj_section *section) + struct symtab *s = NULL; + struct symtab *best_s = NULL; + struct objfile *objfile; +- CORE_ADDR distance = 0; ++ CORE_ADDR distance = 0, start, end; + struct minimal_symbol *msymbol; + + /* If we know that this is not a text address, return failure. This is +@@ -2117,10 +2117,20 @@ find_pc_sect_symtab (CORE_ADDR pc, struct obj_section *section) + bv = BLOCKVECTOR (s); + b = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); + +- if (BLOCK_START (b) <= pc +- && BLOCK_END (b) > pc +- && (distance == 0 +- || BLOCK_END (b) - BLOCK_START (b) < distance)) ++ start = BLOCK_START (b); ++ end = BLOCK_END (b); ++ ++ /* ++ * If we have an addrmap mapping code addresses to blocks, and pc ++ * is in the range [start, end), let's use it. ++ */ ++ if ((pc >= start && pc < end) && BLOCKVECTOR_MAP (bv)) { ++ if (addrmap_find (BLOCKVECTOR_MAP (bv), pc)) ++ return s; ++ } ++ ++ if ((pc >= start && pc < end) && ((distance == 0) ++ || (end - start < distance))) + { + /* For an objfile that has its functions reordered, + find_pc_psymtab will find the proper partial symbol table -- 2.29.2