Bug 30665 - DAP Server: Relative paths in stacktrace response
Summary: DAP Server: Relative paths in stacktrace response
Status: RESOLVED FIXED
Alias: None
Product: gdb
Classification: Unclassified
Component: dap (show other bugs)
Version: HEAD
: P2 normal
Target Milestone: 14.1
Assignee: Tom Tromey
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-07-22 23:49 UTC by Vladimir Makaev
Modified: 2023-08-01 18:56 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2023-07-24 00:00:00


Attachments
Log files and main.rs (8.83 KB, application/zip)
2023-07-22 23:49 UTC, Vladimir Makaev
Details
patch (314 bytes, patch)
2023-07-23 14:57 UTC, Vladimir Makaev
Details | Diff
patch (1.97 KB, patch)
2023-07-24 15:02 UTC, Tom Tromey
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Makaev 2023-07-22 23:49:31 UTC
Created attachment 14996 [details]
Log files and main.rs

When debugging with newly added DAP server my VSCode shows me and error 

"Could not load source 'main.rs': 'source'."

The same binary debugged with LLDB DAP works correctly. Most likely the issue is due to some responses from DAP having relative path instead of absolute path

Attaching logs from debugging session with gdb and lldb and also a main.rs program.


(to compile I used "rustc -g main.rs")
Comment 1 Vladimir Makaev 2023-07-23 14:57:13 UTC
Created attachment 14997 [details]
patch

Added proposed patch
Comment 2 Tom Tromey 2023-07-23 17:48:09 UTC
The gdb log has:

4:38:59 PM  <-- stackTrace
{"request_seq":11,"type":"response","command":"stackTrace","body":{"stackFrames":[{"id":0,"name":"main::main","line":3,"column":0,"instructionPointerReference":"0x555555408175","source":{"name":"main.rs","path":"main.rs","sourceReference":0}}]},"success":true,"seq":37}

... whereas the lldb log uses "path":"/home/vmakaev/gdb-test/main.rs".

gdb also sends this "path" value in other spots, so it seems specific
to stack trace.
Comment 3 Tom Tromey 2023-07-23 17:48:56 UTC
That patch would work except we recently changed this code to use
frame filters.
Perhaps FrameDecorator needs to change.
Comment 4 Tom Tromey 2023-07-24 14:56:00 UTC
I think it's kind of difficult to write a test for this
that can live in-tree, due to how the test suite works.
Anyway I have a patch you can try, will upload shortly.
Comment 5 Tom Tromey 2023-07-24 15:00:52 UTC
Maybe the testing could be done by also implementing 'cwd'
in the launch request, a la https://github.com/eclipse-cdt-cloud/cdt-gdb-adapter/issues/90
Comment 6 Tom Tromey 2023-07-24 15:02:23 UTC
Created attachment 15006 [details]
patch

Could you try this patch in your setup?
Comment 7 Tom Tromey 2023-07-24 16:26:19 UTC
The "cwd" thing is super wrong because what really matters is
passing a relative file name to gcc.
Comment 8 Vladimir Makaev 2023-07-24 17:20:49 UTC
I've updated my remote branch to point to the latest code (I think I had some mirror before which wasn't updated). 

After applying the patch I confirm the issue is fixed. Thanks for looking into it!
Comment 9 Tom Tromey 2023-07-24 18:23:37 UTC
Mine.
Comment 11 Sourceware Commits 2023-08-01 18:55:54 UTC
The master branch has been updated by Tom Tromey <tromey@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=65403bd0ed22f7c26f972449403c97ff5e998b04

commit 65403bd0ed22f7c26f972449403c97ff5e998b04
Author: Tom Tromey <tromey@adacore.com>
Date:   Mon Jul 24 08:48:00 2023 -0600

    Full paths in DAP stackTrace responses
    
    Vladimir Makaev noticed that, in some cases, a DAP stackTrace response
    would include a relative path name for the "path" component.
    
    This patch changes the frame decorator code to add a new DAP-specific
    decorator, and changes the DAP entry point to frame filters to use it.
    This decorator prefers the symtab's full name, and does not fall back
    to the solib's name.
    
    I'm not entirely happy with this patch, because if a user frame filter
    uses FrameDecorator, it may still do the wrong thing.  It would be
    better to have frame filters return symtab-like objects instead, or to
    have a separate method to return the full path to the source file.
    
    I also tend to think that the solib fallback behavior of
    FrameDecorator is a mistake.  If this is ever needed, it seems to me
    that it should be a separate method.
    
    Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=30665
Comment 12 Tom Tromey 2023-08-01 18:56:45 UTC
Fixed.