On Mac OS X, how can you get a debug build of System/LibC for source level debugging? - debugging

I downloaded LibC source from opensource.apple.com, but since it's part of one monolithic library /usr/lib/libSystem.B.dylib would I have to somehow rebuild the entire thing?
I have a BSD command line program, ported from Linux. I want to be able to set breakpoints in LibC functions and step through. I'm trying to close in on what seems to be heap corruption in my program (which doesn't occur on Linux - I've already ported back to Linux and run memcheck there.)

Have you take a look at the Kernel Debug Kit from Apple (http://developer.apple.com/sdk/) ? I know that it contains kernel symbols, but I am not sure if libc is part of the SDK.

You can build Valgrind yourself - either use the last version released on 10.5, or look on the bug tracker for the Snow Leopard support bug, which has a patch.
Alternately, try the memory debugging tools in the malloc(3) manual.

Related

How can I use the pre-compiled binaries to update to clang 3.3 on Mac OS 10.6.x?

I'm trying to install/update my clang from Apple clang version 1.7 (tags/Apple/clang-77) (based on LLVM 2.9svn) to clang version 3.3. I've downloaded the pre-compiled binaries into usr/bin/, as suggested by other posts (How can I update clang to 3.3 on Mac OS X 10.6).
The point of this installation/update is to be able to use C++ code (not written by me, and written for a newer machine OS 10.8.x) on my mac. I would preferentially use Xcode to update this, but unfortunately, Apple has not made the necessary version of Xcode available for free without a developer's subscription.
I've edited my PATH and LD_LIBRARY_PATH to include clang3.3/bin/ and clang3.3/lib, but I get an "Illegal Instruction" error and it's not clear to me why this is.
What I'd really like is to try the whole process again from the beginning with a step-by-step outline of the process, like is seen here (How to install clang pre-built binaries ubuntu 12.04), except for Mac OSX system, not Ubuntu.
I realize there are some previous threads that ask almost the same question, but I am asking specifically for these versions (and from a standpoint that includes very little experience installing via terminal/understanding pathways/etc.).
Thanks for any help.

Why do OCaml binaries crash on Mac OS X 10.8 (Mountain Lion)?

OCaml programs which worked perfectly on Lion fail on Mountain Lion, segfaulting on startup in OCaml runtime code:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
0x00007fff908e1f88 in large_malloc ()
There appears to be a widespread problem with the native-compiled (ocamlopt) OCaml runtime when backtraces are enabled which is new to Mountain Lion. This same crash affects the startup of any OCaml binaries which are:
Native compiled (as opposed to bytecode)
Run with backtraces enabled (e.g. via OCAMLRUNPARAM=b)
This even includes parts of the OCaml compiler toolchain, itself, which will suddenly stop working after an upgrade to 10.8.
This still affects the OCaml SVN trunk (4.01.dev) as of 2012-07-19.
The workaround is to disabled backtraces when working with native compiled binaries (unset OCAMLRUNPARAM, or remove b from your parameter string).
update:
The underlying bug appears to be due to insufficient stack alignment in the OCaml runtime implementation. Since the originally post, this is now being tracked and fixed on the OCaml bug tracker. For now, however, the workaround remains the only simple choice.
The problem may be solved, there's an explanation and a patch here in OCaml's bugtracker.

Where is Mac OS X Debugging Interface

I am new to UNIX and Mac OS X systems and wondering how debugging on Max OS X works. I am from Windows world and I am familiar with debugging system in Windows like attaching to a process with DebugActiveProcess, reading/writing memory with Read/WriteProcessMemory and so on...
I don't know if Mac OS X's debugging also woriking like Windows but
I want to know how a debugger in Max OS X communicates with a target process. Can anyone give me some hits of a start point or documents where I should read first?
The debugging interface on OS X and most Unixes is called ptrace.
Type man ptrace at a command prompt for information on how ptrace communicates between processes, and also have a look at the header at /usr/include/sys/ptrace.h
The typical debuggers are gbd and (recently) lldb. Many IDEs on OS X also use these. So.. "man gdb" is a good starting point.
As user1118321 mentioned, installing the Xcode toolset would be a good idea, if you've not done so already. It includes compilers, an IDE, debuggers, profilers, and graphical programs for these tools.
You didn't state which language, or tools you're using, so for the purposes of this answer I'll assume you're using Objective-C with either gcc or clang to compile your code and link it into an executable. If you're using some other language, such as java or ruby, the equivalent from windows probably exists for OS X as well.
In general, unix uses GDB for debugging, and OS X is no different. You won't always attach it to a running process, I find that's more common to start a process in the debugger, although there do exist tools (such as Instruments) that will profile a running process.
If you're using XCode, there's a whole suite of debugging tools built in that use gdb under the hood. I suggest you start reading some of the developer documentation here http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/ios_development_workflow/130-Debugging_Applications/debugging_applications.html and then ask around if there's something in particular you want to know about.
If you've installed Xcode, look at all of the applications installed in /Developer/Applications, at a minimum you should find
Xcode - write and debug, design interfaces here
Instruments - profile your application, look for memory leaks
Icon Composer - create slick icons for your applications
Graphics Tools - used to help work with OpenGL and Quartz mainly

Debugging an OSX program on Snow Leopard, which was build on Lion

I have a program which I build using automatic-ref-counting and the Lion SDK. This program doesn't behave as expected in Snow Leopard, (One view won't be loaded and opening a document hangs the program.) so I want to debug it there. But because I can't compile it under Snow Leopard I have no idea how to do so.
So how do I get the debugging symbols into gdb or can I debug this thing in Xcode - is there probably a remote way or something like that?
You can either debug remotely via gdbserver:
snow-leopard$ gdbserver :10000 /path/to/exe
lion$ gdb /path/to/exe
(gdb) target remote snow-leopard:10000
A simpler way is to copy your entire source and build directory to snow-leopard and debug with GDB locally. Even though you didn't build there, GDB should still be able to find everything it needs.
Sorry to say, my research shows that the "g++" compiler on Snow Leopard no longer places symbols in the linked module that have any meaning to "gdb". The only symbols found are the made-up symbols created to make ALL symbols unique. Here is a brief sample:
`_Z5DoSVCi', function, 0x151dd
`_Z7SEBTrapv', function, 0x1383c
Those same symbols in Tiger were like this:
`_Z5DoSVCi' `DoSVC(int)', FUNCTION, 0x1394c
`_Z7SEBTrapv' `SEBTrap()', FUNCTION, 0xf994
The "signature" is what "gdb" needs to resolve things like: break emsvc.c:DoSVC
Furthermore, you must still have all the "object decks", like emsvc.o, because Snow Leopard's "g++" apparently does not carry the symbols in the linked module anymore.
I brought a "g++" compiled module linked on Tiger (Intel-based) over to Snow Leopard without object decks, and "gdb" was able to handle it perfectly, including setting breakpoints. Apparently, "g++" or the linker isn't producing proper modules for "gdb" on Snow Leopard.

compile lanshark on mac

I am trying to compile lanshark for mac, but do not know how to compile on mac. I am guessing that it is possible to compile linux source code on mac. if not how can i get this program to run?
A mac is, under the hood, a BSD 'darwin' box.
Go and take a look at the MacPorts webpage. You'll find lots of interesting information (like where to get a compiler etc ) there.
Another place to go for an apple development environment is apple (xcode) ...
It should be possible to get that to run, but it will be a bit of work. The source may need a small amount of modification, depending on exactly how the protocol works (if they're using raw ethernet, that is done quite differently). Also, the OS X linker (ld) works completely differently to the Linux linker, and so the build system will need a bit of tinkering.
However, the compilers and build utilities are in the XCode bundle on your install disk, or at the download link in the other answer, so install that and give it a go. If you're lucky, just following the Linux instructions will build it.

Resources