Skip to content

Commit 9bec77c

Browse files
author
philippe
committed
Add a gdbxrv monitor command to print the CFI unwind info for an address+len
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15306 a5019735-40e9-0310-863c-91ae7b9d1cf9
1 parent d343ed4 commit 9bec77c

File tree

6 files changed

+63
-3
lines changed

6 files changed

+63
-3
lines changed

coregrind/m_debuginfo/debuginfo.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2828,6 +2828,37 @@ Addr ML_(get_CFA) ( Addr ip, Addr sp, Addr fp,
28282828
# endif
28292829
}
28302830

2831+
void VG_(ppUnwindInfo) (Addr from, Addr to)
2832+
{
2833+
DebugInfo* di;
2834+
CFSI_m_CacheEnt* ce;
2835+
Addr ce_from;
2836+
CFSI_m_CacheEnt* next_ce;
2837+
2838+
2839+
ce = cfsi_m_cache__find(from);
2840+
ce_from = from;
2841+
while (from <= to) {
2842+
from++;
2843+
next_ce = cfsi_m_cache__find(from);
2844+
if ((ce == NULL && next_ce != NULL)
2845+
|| (ce != NULL && next_ce == NULL)
2846+
|| (ce != NULL && next_ce != NULL && ce->cfsi_m != next_ce->cfsi_m)
2847+
|| from > to) {
2848+
if (ce == NULL) {
2849+
VG_(printf)("[%#lx .. %#lx]: no CFI info\n", ce_from, from-1);
2850+
} else {
2851+
di = ce->di;
2852+
ML_(ppDiCfSI)(di->cfsi_exprs,
2853+
ce_from, from - ce_from,
2854+
ce->cfsi_m);
2855+
}
2856+
ce = next_ce;
2857+
ce_from = from;
2858+
}
2859+
}
2860+
}
2861+
28312862

28322863
/* The main function for DWARF2/3 CFI-based stack unwinding. Given a
28332864
set of registers in UREGS, modify it to hold the register values

coregrind/m_debuginfo/storage.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,12 @@ void ML_(ppDiCfSI) ( const XArray* /* of CfiExpr */ exprs,
142142
} \
143143
} while (0)
144144

145-
VG_(printf)("[%#lx .. %#lx]: ", base,
146-
base + (UWord)len - 1);
145+
if (base != 0 || len != 0)
146+
VG_(printf)("[%#lx .. %#lx]: ", base,
147+
base + (UWord)len - 1);
148+
else
149+
VG_(printf)("[]: ");
150+
147151
switch (si_m->cfa_how) {
148152
case CFIC_IA_SPREL:
149153
VG_(printf)("let cfa=oldSP+%d", si_m->cfa_off);

coregrind/m_gdbserver/server.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ int handle_gdb_valgrind_command (char *mon, OutputSink *sink_wanted_at_return)
248248
" v.info exectxt : show stacktraces and stats of all execontexts\n"
249249
" v.info scheduler : show valgrind thread state and stacktrace\n"
250250
" v.info stats : show various valgrind and tool stats\n"
251+
" v.info unwind <addr> [<len>] : show unwind debug info for <addr> .. <addr+len>\n"
251252
" v.set debuglog <level> : set valgrind debug log level to <level>\n"
252253
" v.set hostvisibility [yes*|no] : (en/dis)ables access by gdb/gdbserver to\n"
253254
" Valgrind internal host status/memory\n"
@@ -364,7 +365,7 @@ int handle_gdb_valgrind_command (char *mon, OutputSink *sink_wanted_at_return)
364365
wcmd = strtok_r (NULL, " ", &ssaveptr);
365366
switch (kwdid = VG_(keyword_id)
366367
("all_errors n_errs_found last_error gdbserver_status memory"
367-
" scheduler stats open_fds exectxt location",
368+
" scheduler stats open_fds exectxt location unwind",
368369
wcmd, kwd_report_all)) {
369370
case -2:
370371
case -1:
@@ -456,6 +457,17 @@ int handle_gdb_valgrind_command (char *mon, OutputSink *sink_wanted_at_return)
456457
ret = 1;
457458
break;
458459
}
460+
case 10: { /* unwind */
461+
Addr address;
462+
SizeT sz = 0;
463+
if (VG_(strtok_get_address_and_size) (&address,
464+
&sz, &ssaveptr)) {
465+
VG_(ppUnwindInfo) (address, address + sz - 1);
466+
}
467+
ret = 1;
468+
break;
469+
}
470+
459471
default:
460472
vg_assert(0);
461473
}

coregrind/pub_core_debuginfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ extern Bool VG_(use_FPO_info) ( /*MOD*/Addr* ipP,
165165
Addr min_accessible,
166166
Addr max_accessible );
167167

168+
/* Print the unwind info (if there is some) for the given address
169+
range [from,to]. */
170+
extern void VG_(ppUnwindInfo) (Addr from, Addr to);
171+
168172
/* AVMAs for a symbol. Usually only the lowest address of the entity.
169173
On ppc64 platforms, also contains tocptr and local_ep.
170174
These fields should only be accessed using the macros

docs/xml/manual-core-adv.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,14 @@ problems or bugs.</para>
14781478
</para>
14791479
</listitem>
14801480

1481+
<listitem>
1482+
<para><varname>v.info unwind &lt;addr&gt; [&lt;len&gt;]</varname> shows
1483+
the CFI unwind debug info for the address range [addr, addr+len-1].
1484+
The default value of &lt;len&gt; is 1, giving the unwind information
1485+
for the instruction at &lt;addr&gt;.
1486+
</para>
1487+
</listitem>
1488+
14811489
<listitem>
14821490
<para><varname>v.set debuglog &lt;intvalue&gt;</varname> sets the
14831491
Valgrind debug log level to &lt;intvalue&gt;. This allows to

gdbserver_tests/mchelp.stdoutB.exp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ debugging valgrind internals monitor commands:
6565
v.info exectxt : show stacktraces and stats of all execontexts
6666
v.info scheduler : show valgrind thread state and stacktrace
6767
v.info stats : show various valgrind and tool stats
68+
v.info unwind <addr> [<len>] : show unwind debug info for <addr> .. <addr+len>
6869
v.set debuglog <level> : set valgrind debug log level to <level>
6970
v.set hostvisibility [yes*|no] : (en/dis)ables access by gdb/gdbserver to
7071
Valgrind internal host status/memory

0 commit comments

Comments
 (0)