diff options
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/findvar.c | 40 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-label-symbol-value.c | 38 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-label-symbol-value.exp | 39 |
3 files changed, 103 insertions, 14 deletions
diff --git a/gdb/findvar.c b/gdb/findvar.c index e609358..a5e2703 100644 --- a/gdb/findvar.c +++ b/gdb/findvar.c @@ -593,20 +593,32 @@ language_defn::read_var_value (struct symbol *var, return v; case LOC_LABEL: - /* Put the constant back in target format. */ - v = allocate_value (type); - if (overlay_debugging) - { - struct objfile *var_objfile = var->objfile (); - addr = symbol_overlayed_address (var->value_address (), - var->obj_section (var_objfile)); - store_typed_address (value_contents_raw (v).data (), type, addr); - } - else - store_typed_address (value_contents_raw (v).data (), type, - var->value_address ()); - VALUE_LVAL (v) = not_lval; - return v; + { + /* Put the constant back in target format. */ + if (overlay_debugging) + { + struct objfile *var_objfile = var->objfile (); + addr = symbol_overlayed_address (var->value_address (), + var->obj_section (var_objfile)); + } + else + addr = var->value_address (); + + /* First convert the CORE_ADDR to a function pointer type, this + ensures the gdbarch knows what type of pointer we are + manipulating when value_from_pointer is called. */ + type = builtin_type (var->arch ())->builtin_func_ptr; + v = value_from_pointer (type, addr); + + /* But we want to present the value as 'void *', so cast it to the + required type now, this will not change the values bit + representation. */ + struct type *void_ptr_type + = builtin_type (var->arch ())->builtin_data_ptr; + v = value_cast_pointers (void_ptr_type, v, 0); + VALUE_LVAL (v) = not_lval; + return v; + } case LOC_CONST_BYTES: if (is_dynamic_type (type)) diff --git a/gdb/testsuite/gdb.python/py-label-symbol-value.c b/gdb/testsuite/gdb.python/py-label-symbol-value.c new file mode 100644 index 0000000..94bdae6 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-label-symbol-value.c @@ -0,0 +1,38 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2022 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +volatile int global_var = 1; + +int +get_value () +{ + return global_var; +} + +int +main (void) +{ + int value = get_value (); + if (value > 0) + goto some_label; + + return 1; + + some_label: + + return 0; +} diff --git a/gdb/testsuite/gdb.python/py-label-symbol-value.exp b/gdb/testsuite/gdb.python/py-label-symbol-value.exp new file mode 100644 index 0000000..44321e5 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-label-symbol-value.exp @@ -0,0 +1,39 @@ +# Copyright 2022 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Check that GDB handles the user asking for the value of a label +# symbol (i.e. a symbol for a goto label). + +load_lib gdb-python.exp +standard_testfile + +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } { + return -1 +} + +# Skip all tests if Python scripting is not enabled. +if { [skip_python_tests] } { continue } + +if ![runto_main] { + return -1 +} + +# Use Python to print the value of the 'some_label' symbol. +gdb_test "python frame = gdb.selected_frame()" +gdb_test "python frame_pc = frame.pc()" +gdb_test "python block = gdb.current_progspace().block_for_pc(frame_pc)" +gdb_test "python symbol,_ = gdb.lookup_symbol('some_label', block, gdb.SYMBOL_LABEL_DOMAIN)" +gdb_test "python print(str(symbol.value()))" "$hex <main\\+$decimal>" +gdb_test "python print(str(symbol.value().type))" "void \\*" |