question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

break-insert for lldb-mi no longer requires 'on'

See original GitHub issue

In this line, we have a comment that break-insert requires on for lldb-mi: https://github.com/microsoft/MIEngine/blob/2bb9706607edf0ce839bab4eb131adc8a555b6ec/src/MIDebugEngine/Engine.Impl/DebuggedProcess.cs#L872

This is no longer true (presumably, it has been fixed upstream in lldb-mi): https://github.com/lldb-tools/lldb-mi (maybe this change: https://github.com/lldb-tools/lldb-mi/commit/e448e35a9e4da5b5a4f0f80530ba30d5a619cb3e#diff-16ecaed41b16ef0b1fd18b3f74b1a2f2).

I think fixing this will allow us to fix debugging on macOS using vscode-cpptools: https://github.com/microsoft/vscode-cpptools/issues/3829

Taking the latest version of lldb-mi from GitHub, and building it:

  • Including -break-insert -f on main does not work:
lldbmitest) BenMBP:attach ben$ ../../build/src/lldb-mi
(gdb)
-file-exec-and-symbols ../testdata/simple/simple
^done
(gdb)
=library-loaded,id="/Users/ben/Development/llvm-project/lldb-mi/test/testdata/simple/simple",target-name="/Users/ben/Development/llvm-project/lldb-mi/test/testdata/simple/simple",host-name="/Users/ben/Development/llvm-project/lldb-mi/test/testdata/simple/simple",symbols-loaded="1",symbols-path="/Users/ben/Development/llvm-project/lldb-mi/test/testdata/simple/simple.dSYM/Contents/Resources/DWARF/simple",loaded_addr="-",size="4096"
-break-insert -f on main
^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0xffffffffffffffff",func="??",file="??",fullname="??/??",line="0",pending=["on"],times="0",original-location="on"}
(gdb)
=breakpoint-modified,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0xffffffffffffffff",func="??",file="??",fullname="??/??",line="0",pending=["on"],times="0",original-location="on"}
(gdb)

As you can see, the breakpoint is pending and has no file/line info.

  • Including -break-insert -f main works:
(lldbmitest) BenMBP:attach ben$ ../../build/src/lldb-mi
(gdb)
-file-exec-and-symbols ../testdata/simple/simple
^done
(gdb)
=library-loaded,id="/Users/ben/Development/llvm-project/lldb-mi/test/testdata/simple/simple",target-name="/Users/ben/Development/llvm-project/lldb-mi/test/testdata/simple/simple",host-name="/Users/ben/Development/llvm-project/lldb-mi/test/testdata/simple/simple",symbols-loaded="1",symbols-path="/Users/ben/Development/llvm-project/lldb-mi/test/testdata/simple/simple.dSYM/Contents/Resources/DWARF/simple",loaded_addr="-",size="4096"
-break-insert -f main
^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0000000100000f26",func="main",file="simple.cpp",fullname="/Users/ben/Development/llvm-project/lldb-mi/test/testdata/simple/simple.cpp",line="15",pending=["main"],times="0",original-location="main"}
(gdb)
=breakpoint-modified,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x0000000100000f26",func="main",file="simple.cpp",fullname="/Users/ben/Development/llvm-project/lldb-mi/test/testdata/simple/simple.cpp",line="15",pending=["main"],times="0",original-location="main"}
(gdb)

as you can see, this works and resolves the breakpoint, and we can see that the breakpoint is actually triggered, hence this lldb-mi could be used with MIEngine (via vscode-cpptools) to fix the macOS breakpoints-not-triggering issue (referenced above):

(gdb)
-exec-run

<snip uninteresting stuff>

(gdb)
*stopped,reason="breakpoint-hit",disp="del",bkptno="1",frame={level="0",addr="0x0000000100000f26",func="main",args=[{name="argc",value="1"}],file="simple.cpp",fullname="/Users/ben/Development/llvm-project/lldb-mi/test/testdata/simple/simple.cpp",line="15"},thread-id="1",stopped-threads="all"
(gdb)

I would send a PR to remove this lldb-mi workaround, but I can’t actually build this project as I don’t have Windows.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:15 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
puremourningcommented, Jan 4, 2020

Woo \o/. with the above PR (#950) and the latest lldb-mi including the new-console patch vimspector regression tests finally pass on macOS Catalina!

BenMBP:vimspector ben$ ./run_tests
Testing with VIMSPECTOR_MIMODE=lldb
%SETUP - Building test programs...
~/.vim/bundle/vimspector/tests/testdata/cpp/simple ~/.vim/bundle/vimspector
rm -f simple variables
rm -rf simple.dSYM variables.dSYM
c++ -g -O0 -std=c++17    simple.cpp   -o simple
~/.vim/bundle/vimspector
%DONE - built test programs
Running Vimspector Vim tests

%RUN: breakpoints.test.vim
%PASS: breakpoints.test.vim PASSED

%RUN: language_go.test.vim
%PASS: language_go.test.vim PASSED

%RUN: language_python.test.vim
%PASS: language_python.test.vim PASSED

%RUN: tabpage.test.vim
%PASS: tabpage.test.vim PASSED

All done.

Now, to fix vscode-python which doesn’t work with node 13.

1reaction
puremourningcommented, Jan 4, 2020

@WardenGnaw I tried testing your fixLLDB branch, it doesn’t work - it just hangs. I think this is because it sends the command too early, or it never reads the command result ? Not sure.

Here’s the output:

1: (124) LaunchOptions<LocalLaunchOptions xmlns='http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014'
1: (146) LaunchOptions  ExePath='/Users/ben/Development/vim/src/vim'
1: (147) LaunchOptions  WorkingDirectory='/Users/ben/Development/vim'
1: (147) LaunchOptions  ExeArguments='-Nu NONE'
1: (147) LaunchOptions  MIMode='lldb'
1: (147) LaunchOptions  MIDebuggerPath='/Users/ben/Development/llvm-project/lldb-mi/build/src/lldb-mi'
1: (147) LaunchOptions  WaitDynamicLibLoad='false'
1: (147) LaunchOptions  ExternalConsole='true'
1: (147) LaunchOptions>
1: (147) LaunchOptions    <Environment>
1: (147) LaunchOptions        <EnvironmentEntry Name='VIMRUNTIME' Value='/Users/ben/Development/vim/runtime' />
1: (147) LaunchOptions    </Environment>
1: (147) LaunchOptions</LocalLaunchOptions>
1: (233) Starting: "/Users/ben/Development/llvm-project/lldb-mi/build/src/lldb-mi" --interpreter=mi
1: (255) DebuggerPid=98248
1: (758) ->(gdb)
1: (772) <-1001-break-insert -f main
1: (773) ->1001^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0xffffffffffffffff",func="??",file="??",fullname="??/??",line="0",pending=["main"],times="0",original-location="main"}
1: (774) ->(gdb)
... no further....

Looks to me like it’s never returning from RequiresOnKeywordForBreakInsert() Here’s my quick implementation of the new-console command for the record:

commit d48fc781fabff4bc1b60256673c6ed072814b78c (HEAD -> master, pm/master)
Author: Ben Jackson <puremourning@gmail.com>
Date:   Sat Jan 4 14:37:46 2020 +0000

    Support new-console GDB command.

    This is a simple way to make applications launch in a new Terminal on
    macOS. There's actually a LLDB launch flag lldb:eLaunchFlagLaunchInTTY,
    but it wasn't obvious to me how/where to store launcg options in
    lldb-mi, so setting the environment variable works just as well.

diff --git a/src/MICmdCmdGdbSet.cpp b/src/MICmdCmdGdbSet.cpp
index 162e3d5..9330a91 100644
--- a/src/MICmdCmdGdbSet.cpp
+++ b/src/MICmdCmdGdbSet.cpp
@@ -16,6 +16,7 @@
 #include "MICmnLLDBDebugSessionInfo.h"
 #include "MICmnMIResultRecord.h"
 #include "MICmnMIValueConst.h"
+#include <cstdlib>

 // Instantiations:
 const CMICmdCmdGdbSet::MapGdbOptionNameToFnGdbOptionPtr_t
@@ -28,6 +29,7 @@ const CMICmdCmdGdbSet::MapGdbOptionNameToFnGdbOptionPtr_t
         {"solib-search-path", &CMICmdCmdGdbSet::OptionFnSolibSearchPath},
         {"disassembly-flavor", &CMICmdCmdGdbSet::OptionFnDisassemblyFlavor},
         {"fallback", &CMICmdCmdGdbSet::OptionFnFallback},
+        {"new-console", &CMICmdCmdGdbSet::OptionFnNewConsole},
         {"breakpoint", &CMICmdCmdGdbSet::OptionFnBreakpoint}};

 //++
@@ -208,6 +210,41 @@ bool CMICmdCmdGdbSet::GetOptionFn(const CMIUtilString &vrPrintFnName,
   return false;
 }

+bool CMICmdCmdGdbSet::OptionFnNewConsole(
+  const CMIUtilString::VecString_t &vrWords) {
+  bool bNewConsole = false;
+  bool bOk = true;
+
+  if (vrWords.size() > 1)
+    // Too many arguments.
+    bOk = false;
+  else if (vrWords.size() == 0)
+    // If no arguments, default is "on".
+    bNewConsole = true;
+  else if (CMIUtilString::Compare(vrWords[0], "on"))
+    bNewConsole = true;
+  else if (CMIUtilString::Compare(vrWords[0], "off"))
+    bNewConsole = false;
+  else
+    // Unrecognized argument.
+    bOk = false;
+
+  if (!bOk) {
+    // Report error.
+    m_bGbbOptionFnHasError = true;
+    m_strGdbOptionFnError = MIRSRC(IDS_CMD_ERR_GDBSET_OPT_NEWCONSOLE);
+    return MIstatus::failure;
+  }
+
+  // TDDO: Like, set the environment variable ?
+  // Should we maybe set the launch flag too ?
+  if (bNewConsole) {
+    ::setenv( "LLDB_LAUNCH_FLAG_LAUNCH_IN_TTY", "TRUE", false );
+  }
+
+  return MIstatus::success;
+}
+
 //++
 // Details: Carry out work to complete the GDB set option 'target-async' to
 // prepare
diff --git a/src/MICmdCmdGdbSet.h b/src/MICmdCmdGdbSet.h
index c88f997..38f35ae 100644
--- a/src/MICmdCmdGdbSet.h
+++ b/src/MICmdCmdGdbSet.h
@@ -81,6 +81,7 @@ private:
   bool OptionFnDisassemblyFlavor(const CMIUtilString::VecString_t &vrWords);
   bool OptionFnBreakpoint(const CMIUtilString::VecString_t &vrWords);
   bool OptionFnFallback(const CMIUtilString::VecString_t &vrWords);
+  bool OptionFnNewConsole(const CMIUtilString::VecString_t &vrWords);

   // Attributes:
 private:
diff --git a/src/MICmnResources.cpp b/src/MICmnResources.cpp
index 998c79a..6fe2eaf 100644
--- a/src/MICmnResources.cpp
+++ b/src/MICmnResources.cpp
@@ -439,6 +439,8 @@ const CMICmnResources::SRsrcTextData
         {IDS_CMD_ERR_INFO_PRINTFN_FAILED, "The request '%s' failed."},
         {IDS_CMD_ERR_GDBSET_OPT_TARGETASYNC,
          "'target-async' expects \"on\" or \"off\""},
+        {IDS_CMD_ERR_GDBSET_OPT_NEWCONSOLE,
+         "'new-console' expects \"on\" or \"off\""},
         {IDS_CMD_ERR_GDBSET_OPT_BREAKPOINT,
          "'breakpoint' expects \"pending on\" or \"pending off\""},
         {IDS_CMD_ERR_GDBSET_OPT_SOLIBSEARCHPATH,
diff --git a/src/MICmnResources.h b/src/MICmnResources.h
index 111b0c3..195784b 100644
--- a/src/MICmnResources.h
+++ b/src/MICmnResources.h
@@ -263,6 +263,7 @@ enum {
   IDS_CMD_ERR_INFO_PRINTFN_NOT_FOUND,
   IDS_CMD_ERR_INFO_PRINTFN_FAILED,
   IDS_CMD_ERR_GDBSET_OPT_TARGETASYNC,
+  IDS_CMD_ERR_GDBSET_OPT_NEWCONSOLE,
   IDS_CMD_ERR_GDBSET_OPT_BREAKPOINT,
   IDS_CMD_ERR_GDBSET_OPT_SOLIBSEARCHPATH,
   IDS_CMD_ERR_GDBSET_OPT_PRINT_BAD_ARGS,
Read more comments on GitHub >

github_iconTop Results From Across the Web

⚙ D52953 [lldb-mi] Implement -gdb-set breakpoint pending ...
This allows creating pending breakpoint automatically when a location is not found. This is used by some front-ends instead of doing ...
Read more >
interpreter-exec console of lldb command
The --break-insert MI command does a less complicated job that just supports a smaller subset of the gdb breakpoint syntax.
Read more >
Eclipse & lldb-mi (macOSX) breakpoint in dynamically ...
I am developing a C++ dynamically loaded library for PHP which is loaded at run-time. I need to set a breakpoint at a...
Read more >
Debugger lldb-mi no longer present?
Hi, I am using Mohave 10.14.6 on a work computer with XCode 11.2 having recently been upgraded from High Sierra. Before the upgrade,...
Read more >
How to set up debugging on macOS with LLDB-MI
The lldb-mi executable requires LLDB.framework to run. ... you want to use an LLDB.framework that is not installed with Xcode, you need to:....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found