Handle case where DAP line can be None

Message ID 20250106144727.3449963-1-tromey@adacore.com
State New
Headers
Series Handle case where DAP line can be None |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Test passed

Commit Message

Tom Tromey Jan. 6, 2025, 2:47 p.m. UTC
  A comment in bugzilla pointed out a bug in my earlier patch to handle
the DAP "linesStartAt1" setting.  In particular, in the backtrace
code, "line" can be None, which would lead to an exception from
export_line.

This patch fixes the problem.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32468
---
 gdb/python/lib/gdb/dap/bt.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
  

Comments

Tom Tromey Jan. 13, 2025, 2:41 p.m. UTC | #1
>>>>> "Tom" == Tom Tromey <tromey@adacore.com> writes:

Tom> A comment in bugzilla pointed out a bug in my earlier patch to handle
Tom> the DAP "linesStartAt1" setting.  In particular, in the backtrace
Tom> code, "line" can be None, which would lead to an exception from
Tom> export_line.

Tom> This patch fixes the problem.

Tom> Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32468

Since gdb 16 is fast approaching, I'm checking this in now and
backporting it to the branch as well.

thanks,
Tom
  

Patch

diff --git a/gdb/python/lib/gdb/dap/bt.py b/gdb/python/lib/gdb/dap/bt.py
index a27c61a6cda..0fefa694c9a 100644
--- a/gdb/python/lib/gdb/dap/bt.py
+++ b/gdb/python/lib/gdb/dap/bt.py
@@ -84,9 +84,9 @@  def _backtrace(thread_id, levels, startFrame, stack_format):
                 "column": 0,
                 "instructionPointerReference": hex(pc),
             }
-            line = export_line(current_frame.line())
+            line = current_frame.line()
             if line is not None:
-                newframe["line"] = line
+                newframe["line"] = export_line(line)
                 if stack_format["line"]:
                     # Unclear whether export_line should be called
                     # here, but since it's just for users we pick the