Debugging on macOS
Xcode: In addition to Xcode, you should also install the Xcode command line tools. They include LLDB, the default debugger in Xcode on macOS. It supports debugging C, Objective-C and C++ on the desktop and iOS devices and simulator.
.lldbinit: Create or edit
~/.lldbinit
to allow Chromium code to be properly source-mapped.
Attaching to and Debugging Electron
To start a debugging session, open up Terminal and start lldb
, passing a non-release
build of Electron as a parameter.
$ lldb ./out/Testing/Electron.app
(lldb) target create "./out/Testing/Electron.app"
Relevant code files can be found in ./shell/
.
Let’s assume that you want to debug app.setName()
, which is defined in browser.cc
as . Set the breakpoint using the breakpoint
command, specifying
file and line to break on:
Then, start Electron:
(lldb) run
The app will immediately be paused, since Electron sets the app’s name on launch:
(lldb) frame variable
(atom::Browser *) this = 0x0000000108b14f20
(const string &) name = "Electron": {
To do a source level single step in the currently selected thread, execute step
(or s
).
This would take you into name_override_.empty()
. To proceed and do a step over,
run next
(or n
).
NOTE: If you don’t see source code when you think you should, you may not have added the ~/.lldbinit
file above.
To finish debugging at this point, run process continue
. You can also continue until a certain
line is hit in this thread (thread until 100
). This command will run the thread in the current
frame till it reaches line 100 in this frame or stops if it leaves the current frame.
Now, if you open up Electron’s developer tools and call , you will once again hit the breakpoint.
Further Reading
You can also check out LLDB’s fantastic , which will explain more complex debugging scenarios.