XCode: custom lldb or adding args to existing one - xcode

Recently I found that it's possible to debug via lldb remotely but from command line. So the question: is it possible somehow to replace standard lldb with my version or to have any control over command line which is passed from xcode when it's launched.
there are two reason for doing this:
pure remote debugging, extremely convenient when debugging focus/eventTarget issues (window/process activation/deactivation)
debugging of root processes following the manual Debugging in XCode as root . I'm aware about "debug as root" in xcode 6 option, but it doesn't work for me for some reason... Also notice that there an option to select a debugger in lld Debugger/Attach to Process/By Process Identifier (PID) or Name... However the option is only.

Related

Project specific .lldbinit in current working directory not read by Xcode

I want to setup project specific .lldbinit files, so that "everything" would be under version control and easily setup in new computers. However it seems like I can read only ~/.lldbinit file and not any ~/git/project/.lldbinit files.
LLDB manual say:
lldb will read settings/aliases/commands from three files at startup, if
they exist.
First, it will read a ~/.lldbinit-debugger command file. If you are
using the lldb command line interface, this is ~/.lldbinit-lldb. If you
are using lldb inside a GUI debugger like Xcode this will be ~/.lldbinit-
Xcode. This is a useful place to put settings that you want to apply
only when a given lldb command interpreter is used.
Second, ~/.lldbinit is read.
Third, an .lldbinit file in the current working directory (where lldb is
started) will be read.
So my question is: how do I setup Xcode or project to use the "third" option i.e. read .lldbinit file from the current working directory? How would I check or change what's Xcode's "current working directory"?
Xcode now (written with the public Xcode 12) has support for setting a scheme-level LLDB Init File. This can be done as part of the Info tab in the Run phase of the scheme.
Open project in Xcode.
⌘ + Shift + , to open scheme editor.
Select Run then the Info tab.
Edit LLDB Init File value.
Use $(PROJECT_DIR) to reference the directory that contains the project.
Use $(SRCROOT) to reference the target's source root directory.
This is the working directory in which you launch whatever process loads the LLDB framework. Xcode doesn't have a useful working directory (it was / last time I looked), so you can't really use the cwd version.
A solution for Xcode project specific lldb settings that will work in many cases is to put a symbolic breakpoint on main, set it to auto-continue, then put the settings you want in the breakpoint commands of that breakpoint.
It would also be great if Xcode had some UI to specify target-specific lldbinit files.
There is now a "Xcode plugin to load project specific .lldbinit" at https://github.com/alloy/lldb-is-it-not
Xcode now has support for Target specific lldb init files. There's an entry form for the path to the file in the Run scheme for the Xcode target.

GDB command file in XCode

I'd like to add a file to my project that has a list of gbd commands and load that into GDB within xcode at any breakpoint. Looking at GDB documentation I see the "source" commmand, but it is unknown within xcode's gdb. Has anyone had success doing this?
source -f commandfile.gdb
Thanks,
The source command appears to work although no options are supported if you are really using gdb as the debugger. In the debug console make sure it says "(gdb)" as the prompt. The default debugger now is LLDB instead of GDB. You can change this under Product -> Edit Scheme… and select the "Info" tab at the top. The "Debugger" popup will present you with GDB or LLDB.

How can I automatically run my programs in a Terminal window & debug with Xcode?

I am building a program on Mac OS that uses the curses library. When I attempt to run it inside Xcode, I get this error message:
Error opening terminal: unknown.
And then curses calls exit.
Obviously, it works from a Terminal window.
Is it possible to launch my program in a terminal window from Xcode? I know that I can use the "Wait for XXX to launch" option, but a lot of Xcode's helpfulness in starting programs vanishes that way, so I would be looking for another way.
Xcode uses GDB, or LLDB for debugging.
You can invoke them directly from a terminal. This way, your executable will be attached to a working one.
Try:
gdb path/to/my/executable
Then, from the GDB prompt, type:
run
To start your program in debugging mode.
Take a look at the GDB manual for learning stuff like debugging commands, breakpoints, etc.

XCode 4 for Embedded Linux Kernel Development?

I'm trying to use XCode 4 (with external build utility) for embedded Linux on ARM kernel development. Please note that I have all the cross-compilers and tools working from the command line on the Mac, but would like to use XCode for comfort.
The standard make phase (make ARCH=arm CROSS_COMPILE=arm-none-eabi- uImage) seems to work just fine, but can't figure out how to:
(a) Create a target that needs interactive input in the shell (make ARCH=arm menuconfig). This always complains about "Error opening terminal: unknown", and as of XCode 4 it runs in the background. Any ideas how I can open an interactive shell in the foreground?
(b) Use arm-none-eabi-gdb as my debugger. This is optional but would be really neat.
Thanks!
a) Can you figure out how to launch the equivalent of an xterm containing the command? Or some IDE's have a checkbox option to run a command in an interactive window. Finally consider just doing any menuconfig-involved makes from the command line
b) Depends on if xcode can talk gdb's protocol in general. If it can, then its a matter of figuring out the whole gdbserver target launch procedure. If it can't you'll have to do text mode debugging or use a gdb-compatible front end.

Can I use my gdb to debug an XCode project

I have a XCode which builds and runs under XCode.
I would like to know if it is possible to debug it using a gdb I build under Mac OSX (gdb 7 to be specified). If yes, can you please tell me how can I do that?
Thank you.
gdb-7.0 reverse debugging currently can only work with two classes of targets:
1) a remote simulator/emulator/virtual-machine that supports going backwards, or
2) the built in "process record" target, which at present has only been ported to x86-linux, x86-64 linux, and moxie linux.
Well, now -- I take that back. I recently discovered that process record can work with any remote x86 target, so if you're connecting with your macintosh target via "target remote", you might just be able to do it!
There is an online tutorial for process record here:
http://www.sourceware.org/gdb/wiki/ProcessRecord/Tutorial
More info about process record here:
http://www.sourceware.org/gdb/wiki/ProcessRecord
And about gdb reverse debugging here:
http://www.sourceware.org/gdb/wiki/ReverseDebug
So you want to use your own version of gdb to debug your executable? Easy!
Open Terminal, and do something like this:
$ cd <directory where Xcode project lives>
$ cd build/Debug (for example - depends on project configuration)
$ /usr/local/bin/my-gdb ./MyExecutable
Of course, specifying the actual path to your custom gdb version.
XCode's debugger is gdb (likely with Apple-specific modifications.) When you debug an application you can get to the gdb command line by opening the Console from the Run menu.
What requirements are imposed on your application that would require you to debug with your own version of gdb?

Resources