diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 4a624f29cea..1dd4d3e76f1 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2021-06-03 Magne Hov + + PR python/27841 + * eval.c (expression::evaluate): Check inferior_ptid. + 2021-06-03 Pedro Alves * MAINTAINERS (The Official FSF-appointed GDB Maintainers): Remove diff --git a/gdb/eval.c b/gdb/eval.c index 1b3c974009a..659493c8237 100644 --- a/gdb/eval.c +++ b/gdb/eval.c @@ -93,7 +93,7 @@ struct value * expression::evaluate (struct type *expect_type, enum noside noside) { gdb::optional stack_temporaries; - if (target_has_execution () + if (target_has_execution () && inferior_ptid != null_ptid && language_defn->la_language == language_cplus && !thread_stack_temporaries_enabled_p (inferior_thread ())) stack_temporaries.emplace (inferior_thread ()); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 642c18cfe73..afa9ebf9f03 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2021-06-03 Magne Hov + + PR python/27841 + * gdb.python/py-events.exp: Extend inferior exit tests. + * gdb.python/py-events.py: Print inferior exit PID. + 2021-06-03 Hannes Domani * gdb.python/py-symbol.exp: Test symbol constants. diff --git a/gdb/testsuite/gdb.python/py-events.exp b/gdb/testsuite/gdb.python/py-events.exp index e89cd8b021b..753709361f5 100644 --- a/gdb/testsuite/gdb.python/py-events.exp +++ b/gdb/testsuite/gdb.python/py-events.exp @@ -197,18 +197,33 @@ gdb_test_multiple "continue" $test { gdb_test_no_output "delete $second_breakpoint" #test exited event. +proc get_process_id {test} { + global gdb_prompt + gdb_test_multiple "info proc" $test { + -re "process (\\d+).*$gdb_prompt $" { + set process_id $expect_out(1,string) + pass $gdb_test_name + } + } + return ${process_id} +} + +set process_id [get_process_id "get inferior 1 process id"] gdb_test "continue" ".*event type: continue.* .*clear_objfiles\[\r\n\]*progspace: .*py-events.* .*event type: exit.* .*exit code: 12.* .*exit inf: 1.* +.*exit pid: $process_id.* dir ok: True.*" "Inferior 1 terminated." gdb_test "inferior 2" ".*Switching to inferior 2.*" +set process_id [get_process_id "get inferior 2 process id"] gdb_test "continue" ".*event type: continue.* .*event type: exit.* .*exit code: 12.* .*exit inf: 2.* +.*exit pid: $process_id.* dir ok: True.*" "Inferior 2 terminated." @@ -235,3 +250,29 @@ gdb_test "python print(count)" 2 "check for before_prompt event" gdb_test_no_output "xxz" "run a canned sequence" gdb_test "python print(count)" 4 "check for before_prompt event again" + +# Test evaluating expressions from within an inferior exit event handler. This +# used to cause a crash when expression were evaluated as C++. +gdb_test_no_output "set language c++" + +gdb_test_multiline "add exited listener" \ + "python" "" \ + "def increment_foo(_):" "" \ + " gdb.execute('set \$_foo=\$_foo+1')" "" \ + "gdb.events.exited.connect(increment_foo)" "" \ + "end" "" +gdb_test "set \$_foo=0" "" "initialize foo variable" +gdb_test "print \$_foo" "= 0" "check foo initialized" + +with_test_prefix "inferior run exit" { + gdb_run_cmd + gdb_test "" "exited with code.*" "run to exit" + gdb_test "print \$_foo" "= 1" "check foo after run" +} + +with_test_prefix "inferior continue exit" { + gdb_start_cmd + gdb_test "" "Temporary breakpoint .* main .*" "stop on a frame" + gdb_test "continue" "exited with code.*" "continue to exit" + gdb_test "print \$_foo" "= 2" "check foo after start continue" +} diff --git a/gdb/testsuite/gdb.python/py-events.py b/gdb/testsuite/gdb.python/py-events.py index 6a676271b41..1524267117d 100644 --- a/gdb/testsuite/gdb.python/py-events.py +++ b/gdb/testsuite/gdb.python/py-events.py @@ -47,6 +47,7 @@ def exit_handler(event): print("event type: exit") print("exit code: %d" % (event.exit_code)) print("exit inf: %d" % (event.inferior.num)) + print("exit pid: %d" % (event.inferior.pid)) print("dir ok: %s" % str("exit_code" in dir(event)))