How do I debug a process in XCode? - xcode

Here's my situation. I have an app installed on my system. It's running. I also have the source for this app and I've built it in XCode and had it generate dSYM files. I attached to the process in XCode. I've been trying to set breakpoints of the form "-[ClassName methodName]" (without the quotes) however none of my breakpoints are getting hit. Do I have to somehow point XCode to my symbol file or something?

I have never debugged using that method, but there is a much easier way. You can simply click on the line number of a code-bearing line and a blue arrow (a breakpoint) will appear there. When the application reaches one of these lines with a breakpoint, execution will pause an allow you to step through the code one line at a time.

Related

x64dbg cannot open an exe file (but can attach it), why?

If I try to start debugging through the command "Open" of x64dbg, debugging stops without ever starting and a series of missing DLL errors are shown on the screen.
If I just open the program from WIN and THEN I use the attach command by selecting the process, debugging works.
Unfortunately I wanna "investigate" from the moment the program starts and not when it is already started.
How can I solve it ?
You need some anti-anti-debugging plugins (such as ScyllaHide) for x64dbg mentioned in this page to counter anti-debugging attempts and do some patching if needed:
https://github.com/x64dbg/x64dbg/wiki/Plugins

WINDBG doing strange jumps in source code

I have a windows service that was written in VB6 that I want to attach to and debug in WINDBG.
The service is compiled without optimizations (also all boxes in "Advanced Optimizations" are unchecked), and "Create Symbolic Debug Info" is checked. I have the source file of a class I want to set breakpoints in. I can set breakpoints on some lines but not all... even though the lines where I can't put a breakpoint at don't have anything exotic, simple variable assignments and such.
Regardless, the breakpoints I can set are hit when I run the service with the g command, but when I start to "step over" (F10), the code does some strange leaps and doesn't (or at least doesn't appear to) evaluate all lines...
It seems to me that the source file and the symbols file are out of sync, but I just compiled the project and moved the files over to the computer where I want to debug... What could cause the source files and the pdb/dll file of the project to be out of sync?

How can I know because myapplication crash?

Where XCode generate error for application crash ?
I'm crazyng ! My application when open second file xib with webview then it crash. But I don't know why ? how can i Know where is error ?
You need to learn how to use the debugger in Xcode.
Run your app under the debugger then instead if simply getting a stack trace Xcode will stop at the line the fault occurs and show you your code and variables. You can then examine the contents of your variables, the call tree, etc. and hunt down the problem.
Once you know the general area of the problem you can place breakpoints to pause your application before the problem occurs and check whether your variables have the values expected etc. Then you can run till the next breakpoint, or step through your code a line at a time.
You can add code, such as NSAssert's and NSLog's to your app to check progress and display information without stopping the run, etc.
It's a process, and some problems will be harder to track down, but you'll get quicker at it with practice.
The Xcode documentation will tell you all about the debugger.
HTH

How to PROPERLY debug node.js with node inspector?

I have an app built in node.js and I use the node inspector in order to debug.
But it's quite hard because of this:
My breakpoints are never saved after I restart the server
I cannot put a breakpoint on a file that has not loaded yet; so I have to step into from the first script to the one I want; REALLY PAINFULL!
How do you really debug node.js with node inspector?
The videos on how to use node.js are quite misleading as everything is into a module...
http://www.youtube.com/watch?v=AOnK3NVnxL8
or this one the scripts appear are already loaded in the first script
http://www.youtube.com/watch?v=HJOH0-g8f6E&feature=mfu_in_order&list=UL
Edit:
Nobody can answer this question? :s
In javascript you can set breakpoints using the debugger; statement. However, they will only pause node if a debugger is actually attached.
So launch your node script using
node --debug-brk myfile.js
then launch node-inspector and press the play button to continue to the next breakpoint and it will hit your debugger; breakpoint (at least that works for me ATM)
(as noted in the comments: in recent versions of node you no longer have to separately install node-inspector. If you launch node using node --debug-brk --inspect myfile.js you get a url that launches the debugger in your browser).
you still need one extra click after restarting, but at least your breakpoints are saved.
if your breakpoint is not hit automatically, but only after some user action you don't need the --debug-brk of course.
The problem with client-side breakpoints is that it's hard to keep track of the breakpoint position when the file changes. Unlike in an editor, it cannot keep track of lines being changed, etc.
#RyanOlds suggestion of using debugger; statements is also a good one, but you have to make sure the debugger is connected before the statement is evaluated, because it is ignored otherwise. Starting with --debug-brk is a good way to force this, because the execution is paused on the first line allowing you to attach the debugger and then continue the execution.
You could try debugging with node's internal debugger.
Edit: However, according to the v8 DebuggerProtocol it's possible to set breakpoints on script that hasn't been loaded yet AND you can set breakpoints by function, script and more. It should therefore be possible for node-inspector to keep track of your breakpoints (in a session, or whatever). It doesn't do so right now, though.
Maybe if v8 allows a certain piece of code to trigger a breakpoint, similar to nodes debugger?
Edit: It does, you should be able to trigger a break by throwing any old exception (caught or uncaught).
The new version (0.3.x) of node inspector saves breakpoints in browser's local storage and restores them automatically.
https://github.com/node-inspector/node-inspector/pull/116
Try using IntelliJ WebStorm - there's a free trial and licenses aren't outrageously expensive. It lets you save breakpoints in all your files prior to starting up its own internal node process and remembers them across process restarts.
I agree - node-inspector looks brilliant, but is quite useless unless your app has a clear place to set a breakpoint in the top level script just after your source files have loaded, but before you hit the area you want to debug. You can structure your own code this way, but you won't be so lucky with other helpful libraries you want to include. Also... why should a debugging tool dictate your project structure!
Forgetting breakpoints is extremely unhelpful... most of my debug runs take more than one walkthrough, as in other people's code it's easy to step past where you want to be.
You can use node-codein for inspection. It won't do runtime breakpoints but it should ease the inspection process.
https://github.com/ketamynx/node-codein/
Also worth noting.. vscode has a great debugger for node.
https://code.visualstudio.com/
Available on Mac, Linux, & Windows.
It does runtime breakpoints (without the need of writing debugger; statements),
supports variable watches, and even has a call stack window (very nice).
Everything is so automated, it is now my goto over sublime text when using nodejs (and I LOVE sublime).
This is built in now including saving breakpoints. I just tested it in node 7.3.0.
node --inspect --debug-brk app.js
This prints a url like this
To start debugging, open the following URL in Chrome:
chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:9229/c3d5d93e-9d27-41b9-a4da-607e43c9d4f8
Put that in Chrome and you're good to go.
If you want to skip copy/pasting the url, do this:
npm install -g inspect-process
inspect --debug-brk app.js
Unfortunately the inspect-process method doesn't retain the breakpoints :-(.
Here's a video I made: https://youtu.be/rtZKUnks6jI

Extendscript Toolkit not stopping at breakpoints, why?

I am scripting Illustrator CS5 with the Extendscript Toolkit.
I set several breakpoints in my code, they show up as red dots next to the line number. But when I run the script, it executes all the way to the end without stopping and the breakpoint dots turn dark.
What am I missing here?
Thanks!
Check to make sure $.level isn't set somewhere, either in your code or the app's startup script. If $.level is set to 0 or 1, breakpoints are disabled. You might also try explictly setting $.level=2 at the start of your code, to ensure breakpoints are turned on.
This is a common error in the ESTK (Extendscript Toolkit), I believe it's a bug - breakpoints should not get disabled by starting the script.
Most likely pressing F11 (step into) will also make the breakpoints turn into a darker red colour (disabled). But in this state (stepping through the code) you can enable the breakpoints again and they will get hit when you let the script run on (F5).
(Shortcuts are for the Windows version.)
Another thing to try is to first start the script from the scripts panel in InDesign (run it once), and then start it from the ESTK. If you use the targetengine directive to set a specific engine name, this might even be necessary.

Resources