emacs-lsp / dap-mode

Emacs :heart: Debug Adapter Protocol
https://emacs-lsp.github.io/dap-mode
GNU General Public License v3.0
1.3k stars 182 forks source link

[Native Debug gdb] No information about std:: variables #223

Open tosiek88 opened 4 years ago

tosiek88 commented 4 years ago

Hi. I have simple program to test:

#include <iostream>
#include <map>
#include <stdio.h>
#include <vector>
class myTestClass {
public:
  int A = 4;

public:
  myTestClass() { this->A = 5; }
  void testfnc() { this->A = 33; }
};

int main(void) {
  std::cout << "test" << std::endl;
  std::map<char, int> first;

  first['b'] = 30;

  std::map<char, int> second(first.begin(), first.end());
  myTestClass *obj = new myTestClass();
  printf("Hello, world!\n");

  std::vector<int> v{1};
  std::vector<double> d = {1.2};
  int test = 16;
  obj->A = test;
  printf("Variable:%d", obj->A);
  obj->A = test = 12;
  obj->testfnc();
  printf("Variable:%d", obj->A);
  return 0;
}

when I am in dap-debug mode gdb template I am getting limited information about std:: variables like, map, vectors.

variables

in gdb with dashboard extension I am getting : gdb-dashboard

Am I missing something?

yyoncho commented 4 years ago

Screenshot at 2020-02-14 18-54-40

I tested with vscode and it works like that too.

Note that you could execute gdb command in dap-ui-repl.

There is another gdb debug adapter which ships as part of Microsoft cpp tools which we currently do not have adapter but it seems like it works much better:

Screenshot at 2020-02-14 18-59-26

Here it is initial integration with it - https://github.com/emacs-lsp/dap-mode/issues/11#issuecomment-429654509 but someone has to finish it.

tosiek88 commented 4 years ago

Ok thanks? I am quite new in Emacs and ELisp language , what shall be done , I registered this new debug provider,

(dap-register-debug-provider
 "cppdbg" (lambda (conf)
            (plist-put conf
                       :dap-server-path
                       '("/home/tocha/.vscode/extensions/ms-vscode.cpptools-0.26.3/debugAdapters/OpenDebugAD7"))
            conf))

(dap-register-debug-template "C++ Run Configuration"
                             (list :type "cppdbg"
                                   :cwd "/home/tocha/develop/gcc_proces_tut/"
                                   :request "launch"
                                   :program "/home/tocha/develop/gcc_proces_tut/build/debug/gcc_test_project"
                                   :name "Run Configuration"))

A get information that I don't have TERM env variables setup. Minor thing in .zshrc export TERM=alacritty line have been add.

M-x dap-debug then I can choose C++ Run Configuration, Buffer is created: Async Shell Command So this what I understand we can exchange some information between debugger and Emacs?

yyoncho commented 4 years ago

A get information that I don't have TERM env variables setup. Minor thing in .zshrc export TERM=alacritty line have been add.

Can you elaborate?

FYI the autogenerated template on vscode is:

 "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "/home/kyoncho/Sources/lsp-docker/demo-projects/CPP/hello-world/to-debug",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}", ;; replace that with the real value in dap-template.
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
tosiek88 commented 4 years ago

Just my Linux TERM variable for some reason was empty, so I add correct terminal which I am using. Maybe Debugger complain about this because by default "externalConsole" is true ? I am not sure. Generally I will try now this config what You generate in VSCode.

tosiek88 commented 4 years ago

So I am still getting empty Async Shell Command Buffer and nothing else, should I start somehow "/bin/usr/gdb" --interpreter=mi ? I am trying to send some data but I am not sure how should format for request. My knowledge about this is limited I will dig later :)

yyoncho commented 4 years ago

@tosiek88 no worries, we will take a look.

CC @danielmartin - you might be interested too - the MS adapter supports lldb and I suspect it might be better than the alternatives.

tosiek88 commented 4 years ago

Thanks, appreciate your job.

tosiek88 commented 4 years ago

I found that maybe it will be helpful

"valuesFormatting": {
                                "type": "string",
                                "description": "Set the way of showing variable values. 'disabled' - show value as is, 'parseText' - parse debuggers output text into structure, 'prettyPrinters' - enable debuggers custom pretty-printers if there are any",
                                "default": "parseText",
                                "enum": [
                                    "disabled",
                                    "parseText",
                                    "prettyPrinters"
                                ]
                            },

I was trying to put this to template:

(dap-register-debug-template
  "GDB::Run"
  (list :type "gdb"
        :request "launch"
        :valuesFormatting "prettyPrinters"
        :name "GDB::Run"
        :target nil
        :cwd nil))

But it has giving me error if I click on ->Local : Wrong type argument: hash-table-p, 49

tosiek88 commented 4 years ago

debug_1 debug_config In VSCode is working

yyoncho commented 4 years ago

I will take a look tomorrow my time - probably VScode client side is changing the template before sending it to the debug adapter server.

tosiek88 commented 4 years ago

Ok it seems to work, but when inspecting variables which is not evaluated (before breakpoints) whole emacs hangs up . debug_emacas

yyoncho commented 4 years ago

M-x toggle-debug-on-quit and then C-g when it freezes and report the callstack here.

tosiek88 commented 4 years ago
Debugger entered--Lisp error: (quit)
  accept-process-output(nil 0.001)
  dap-request(#s(dap--debug-session :name "GDB::Run" :last-id 21 :proc #<process GDB::Run> :response-handlers #<hash-table eql 1/65 0x1b9c8d9> :parser #s(dap--parser :waiting-for-response nil :response-result nil :headers nil :body nil :reading-body nil :body-length nil :body-received nil :leftovers "") :output-buffer #<buffer *GDB::Run out*> :thread-id 1 :workspace nil :threads (#<hash-table equal 2/65 0x2616ab1>) :thread-states #<hash-table eql 2/65 0x1c79959> :active-frame-id nil :active-frame #<hash-table equal 5/65 0x181a1f5> :cursor-marker nil :state running :breakpoints #<hash-table equal 1/65 0x131fdc1> :thread-stack-frames #<hash-table eql 1/65 0x125a259> :launch-args (:type "gdb" :valuesFormatting "prettyPrinters" :request "launch" :name "GDB::Run" :target "/home/tocha/develop/gcc_proces_tut/build/debug/gcc_test_project" :cwd "/home/tocha/develop/gcc_proces_tut/" :dap-server-path ("node" "/home/tocha/.emacs.d/.local/etc/dap-extension/vscode/webfreak.debug/extension/out/src/gdb.js")) :initialize-result #<hash-table equal 6/65 0x1e121b1> :error-message nil :loaded-sources nil) "variables" :variablesReference 132073)
  dap-ui-render-variables(#s(dap--debug-session :name "GDB::Run" :last-id 21 :proc #<process GDB::Run> :response-handlers #<hash-table eql 1/65 0x1b9c8d9> :parser #s(dap--parser :waiting-for-response nil :response-result nil :headers nil :body nil :reading-body nil :body-length nil :body-received nil :leftovers "") :output-buffer #<buffer *GDB::Run out*> :thread-id 1 :workspace nil :threads (#<hash-table equal 2/65 0x2616ab1>) :thread-states #<hash-table eql 2/65 0x1c79959> :active-frame-id nil :active-frame #<hash-table equal 5/65 0x181a1f5> :cursor-marker nil :state running :breakpoints #<hash-table equal 1/65 0x131fdc1> :thread-stack-frames #<hash-table eql 1/65 0x125a259> :launch-args (:type "gdb" :valuesFormatting "prettyPrinters" :request "launch" :name "GDB::Run" :target "/home/tocha/develop/gcc_proces_tut/build/debug/gcc_test_project" :cwd "/home/tocha/develop/gcc_proces_tut/" :dap-server-path ("node" "/home/tocha/.emacs.d/.local/etc/dap-extension/vscode/webfreak.debug/extension/out/src/gdb.js")) :initialize-result #<hash-table equal 6/65 0x1e121b1> :error-message nil :loaded-sources nil) 132073 (:label #("second: {...}" 0 6 (face font-lock-variable-name-face)) :icon variable :value "{...}" :session #s(dap--debug-session :name "GDB::Run" :last-id 21 :proc #<process GDB::Run> :response-handlers #<hash-table eql 1/65 0x1b9c8d9> :parser #s(dap--parser :waiting-for-response nil :response-result nil :headers nil :body nil :reading-body nil :body-length nil :body-received nil :leftovers "") :output-buffer #<buffer *GDB::Run out*> :thread-id 1 :workspace nil :threads (#<hash-table equal 2/65 0x2616ab1>) :thread-states #<hash-table eql 2/65 0x1c79959> :active-frame-id nil :active-frame #<hash-table equal 5/65 0x181a1f5> :cursor-marker nil :state running :breakpoints #<hash-table equal 1/65 0x131fdc1> :thread-stack-frames #<hash-table eql 1/65 0x125a259> :launch-args (:type "gdb" :valuesFormatting "prettyPrinters" :request "launch" :name "GDB::Run" :target "/home/tocha/develop/gcc_proces_tut/build/debug/gcc_test_project" :cwd "/home/tocha/develop/gcc_proces_tut/" :dap-server-path ("node" "/home/tocha/.emacs.d/.local/etc/dap-extension/vscode/webfreak.debug/extension/out/src/gdb.js")) :initialize-result #<hash-table equal 6/65 0x1e121b1> :error-message nil :loaded-sources nil) :variables-reference 132073 :name "second" :actions (["Set value" dap-ui-set-variable-value]) :key "second" :children #f(compiled-function (&rest args2) #<bytecode 0x1d272d5>)))
  apply(dap-ui-render-variables (#s(dap--debug-session :name "GDB::Run" :last-id 21 :proc #<process GDB::Run> :response-handlers #<hash-table eql 1/65 0x1b9c8d9> :parser #s(dap--parser :waiting-for-response nil :response-result nil :headers nil :body nil :reading-body nil :body-length nil :body-received nil :leftovers "") :output-buffer #<buffer *GDB::Run out*> :thread-id 1 :workspace nil :threads (#<hash-table equal 2/65 0x2616ab1>) :thread-states #<hash-table eql 2/65 0x1c79959> :active-frame-id nil :active-frame #<hash-table equal 5/65 0x181a1f5> :cursor-marker nil :state running :breakpoints #<hash-table equal 1/65 0x131fdc1> :thread-stack-frames #<hash-table eql 1/65 0x125a259> :launch-args (:type "gdb" :valuesFormatting "prettyPrinters" :request "launch" :name "GDB::Run" :target "/home/tocha/develop/gcc_proces_tut/build/debug/gcc_test_project" :cwd "/home/tocha/develop/gcc_proces_tut/" :dap-server-path ("node" "/home/tocha/.emacs.d/.local/etc/dap-extension/vscode/webfreak.debug/extension/out/src/gdb.js")) :initialize-result #<hash-table equal 6/65 0x1e121b1> :error-message nil :loaded-sources nil) 132073 (:label #("second: {...}" 0 6 (face font-lock-variable-name-face)) :icon variable :value "{...}" :session #s(dap--debug-session :name "GDB::Run" :last-id 21 :proc #<process GDB::Run> :response-handlers #<hash-table eql 1/65 0x1b9c8d9> :parser #s(dap--parser :waiting-for-response nil :response-result nil :headers nil :body nil :reading-body nil :body-length nil :body-received nil :leftovers "") :output-buffer #<buffer *GDB::Run out*> :thread-id 1 :workspace nil :threads (#<hash-table equal 2/65 0x2616ab1>) :thread-states #<hash-table eql 2/65 0x1c79959> :active-frame-id nil :active-frame #<hash-table equal 5/65 0x181a1f5> :cursor-marker nil :state running :breakpoints #<hash-table equal 1/65 0x131fdc1> :thread-stack-frames #<hash-table eql 1/65 0x125a259> :launch-args (:type "gdb" :valuesFormatting "prettyPrinters" :request "launch" :name "GDB::Run" :target "/home/tocha/develop/gcc_proces_tut/build/debug/gcc_test_project" :cwd "/home/tocha/develop/gcc_proces_tut/" :dap-server-path ("node" "/home/tocha/.emacs.d/.local/etc/dap-extension/vscode/webfreak.debug/extension/out/src/gdb.js")) :initialize-result #<hash-table equal 6/65 0x1e121b1> :error-message nil :loaded-sources nil) :variables-reference 132073 :name "second" :actions (["Set value" dap-ui-set-variable-value]) :key "second" :children #f(compiled-function (&rest args2) #<bytecode 0x1d272d5>))))
  #f(compiled-function (&rest args2) #<bytecode 0x1d272d5>)((:label #("second: {...}" 0 6 (face font-lock-variable-name-face)) :icon variable :value "{...}" :session #s(dap--debug-session :name "GDB::Run" :last-id 21 :proc #<process GDB::Run> :response-handlers #<hash-table eql 1/65 0x1b9c8d9> :parser #s(dap--parser :waiting-for-response nil :response-result nil :headers nil :body nil :reading-body nil :body-length nil :body-received nil :leftovers "") :output-buffer #<buffer *GDB::Run out*> :thread-id 1 :workspace nil :threads (#<hash-table equal 2/65 0x2616ab1>) :thread-states #<hash-table eql 2/65 0x1c79959> :active-frame-id nil :active-frame #<hash-table equal 5/65 0x181a1f5> :cursor-marker nil :state running :breakpoints #<hash-table equal 1/65 0x131fdc1> :thread-stack-frames #<hash-table eql 1/65 0x125a259> :launch-args (:type "gdb" :valuesFormatting "prettyPrinters" :request "launch" :name "GDB::Run" :target "/home/tocha/develop/gcc_proces_tut/build/debug/gcc_test_project" :cwd "/home/tocha/develop/gcc_proces_tut/" :dap-server-path ("node" "/home/tocha/.emacs.d/.local/etc/dap-extension/vscode/webfreak.debug/extension/out/src/gdb.js")) :initialize-result #<hash-table equal 6/65 0x1e121b1> :error-message nil :loaded-sources nil) :variables-reference 132073 :name "second" :actions (["Set value" dap-ui-set-variable-value]) :key "second" :children #f(compiled-function (&rest args2) #<bytecode 0x1d272d5>)))
  treemacs--do-expand-node(#<marker (moves after insertion) at 79 in *dap-ui-locals*>)
  treemacs-expand-node(nil)
  treemacs-TAB-action(nil)
  funcall-interactively(treemacs-TAB-action nil)
  call-interactively(treemacs-TAB-action nil nil)
  command-execute(treemacs-TAB-action)
yyoncho commented 4 years ago

Ok, will fix that tomorrow my time. What did you do to make it work?

tosiek88 commented 4 years ago
(dap-register-debug-template
  "GDB::Run"
  (list :type "gdb"
        :request "launch"
        :valuesFormatting "prettyPrinters"
        :name "GDB::Run"
        :target nil
        :cwd nil))

valuesFormatting "prettyPrintings", it wasn't work because i have some syntax error, done by mistake in my config.el