diff --git a/gdb/ChangeLog b/gdb/ChangeLog index c6548723d0..6c9b2e0a22 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,11 @@ +2019-08-19 Tom Tromey + + * printcmd.c (do_one_display, info_display_command): Update. + * block.h (contained_in): Return bool. Add allow_nested + parameter. + * block.c (contained_in): Return bool. Add allow_nested + parameter. + 2019-08-19 Tom Tromey * configure: Rebuild. diff --git a/gdb/block.c b/gdb/block.c index 5c6faa8504..ca4dc22cf3 100644 --- a/gdb/block.c +++ b/gdb/block.c @@ -65,25 +65,28 @@ block_gdbarch (const struct block *block) return get_objfile_arch (block_objfile (block)); } -/* Return Nonzero if block a is lexically nested within block b, - or if a and b have the same pc range. - Return zero otherwise. */ +/* See block.h. */ -int -contained_in (const struct block *a, const struct block *b) +bool +contained_in (const struct block *a, const struct block *b, + bool allow_nested) { if (!a || !b) - return 0; + return false; do { if (a == b) - return 1; + return true; + /* If A is a function block, then A cannot be contained in B, + except if A was inlined. */ + if (!allow_nested && BLOCK_FUNCTION (a) != NULL && !block_inlined_p (a)) + return false; a = BLOCK_SUPERBLOCK (a); } while (a != NULL); - return 0; + return true; } diff --git a/gdb/block.h b/gdb/block.h index 9291deb613..4c02e01d90 100644 --- a/gdb/block.h +++ b/gdb/block.h @@ -219,7 +219,15 @@ extern struct symbol *block_containing_function (const struct block *); extern int block_inlined_p (const struct block *block); -extern int contained_in (const struct block *, const struct block *); +/* Return true if block A is lexically nested within block B, or if a + and b have the same pc range. Return false otherwise. If + ALLOW_NESTED is true, then block A is considered to be in block B + if A is in a nested function in B's function. If ALLOW_NESTED is + false (the default), then blocks in nested functions are not + considered to be contained. */ + +extern bool contained_in (const struct block *a, const struct block *b, + bool allow_nested = false); extern const struct blockvector *blockvector_for_pc (CORE_ADDR, const struct block **); diff --git a/gdb/printcmd.c b/gdb/printcmd.c index 7529842e73..9b29b53ca7 100644 --- a/gdb/printcmd.c +++ b/gdb/printcmd.c @@ -1936,7 +1936,8 @@ do_one_display (struct display *d) if (d->block) { if (d->pspace == current_program_space) - within_current_scope = contained_in (get_selected_block (0), d->block); + within_current_scope = contained_in (get_selected_block (0), d->block, + true); else within_current_scope = 0; } @@ -2098,7 +2099,7 @@ Num Enb Expression\n")); else if (d->format.format) printf_filtered ("/%c ", d->format.format); puts_filtered (d->exp_string); - if (d->block && !contained_in (get_selected_block (0), d->block)) + if (d->block && !contained_in (get_selected_block (0), d->block, true)) printf_filtered (_(" (cannot be evaluated in the current context)")); printf_filtered ("\n"); }