Adplus stop debugging process - debugging

I have a stupid question - how can I stop debugging?
I run adplus -crash -0 path -pid number -mss symbols ..
Then I got message that it was attached to the process. I saw logs and mini dumbs in the folder, but I want to stop it. What should I do? I do not see any commands in adplus help to detach it from the process. How can I do it? Can I just close cdb.exe command window or not?
Thanks

You can break into the debugger (in the cdb window, hit Ctrl+C) and then detach using the qd command.
You might want to consider using Procdump to capture crash dumps -- it is much more flexible, easy to use, and supports both x86 and x64 processes in a single package.

Related

How can you debug a process using gdb without pausing it?

I have a process that is already running, and I want to debug it with GDB. I've been using
gdb --pid $PID
However, when I do this, the process pauses. I'd like to attach to the process without pausing it, and look around in its memory while it's still running. Is this possible? Alternatively, is there a way to "fork" the process so that I can look at its memory, without stopping/pausing the process?
There's no way in gdb to attach without some sort of pause.
The Linux kernel provides some support for this via PTRACE_SEIZE, but gdb doesn't use this yet. There's a bug in bugzilla you can track, "Bug 15250 - use PTRACE_SEIZE and PTRACE_INTERRUPT"
Meanwhile you could try setting gdb into "observer mode". Then you could attach and use continue & to continue the process in the background. You may need to set various settings, like target-async, depending on the gdb version.
I am not totally certain if this will work. It is worth a try. Note that there is a window in which the program will be paused. This is unavoidable right now.

Using VMMap in a batch script

I am doing some analysis work on some software we are running where I work. The software seems to have memory issues some where along the line which are proving difficult to track down. We have decided to use Sysinternals VMMap to track the memory being used by the software.
We have VMMap exporting the usage every 20 seconds using Windows scheduler to launch a batch script which pulls back the target process PID and launches VMMap with it. The process runs for a while, output appearing the out directory but after a while it stops. Windows scheduler reports the job ran fine and will start another instance when the trigger is meant, once again with no output.
After a bit of investigation it looks like VMMap is failing to open the process and is trying to report an error through its GUI. Since we are running in batch, we cannot see this error to dismiss it. This is causing numerous process' to be spawned but not actually doing anything.
Has anyone come across this issue when using VMMap, or know of anything that may help? I am thinking there may be some flag I can pass which suppresses messages or maybe some way I can handle it in the batch but Google hasn't helped nor has the Sysinternals forum. Any help would be really appreciated.
VMMap is a GUI tool, so trying to capture its output in an automated way will be difficult. Instead, try using another SysInternals tool, Handle, that captures a lot of the same information, but exports/reports on it in command line, where it can be captured much easier. Alternatively, don't run the output in an auto-repeating way when using VMMap, but instead have your script somehow detect the error or missing expected results/data and stop so the GUI output can be examined.
All Sysinternals tools do pop up a consent dialog for the first time they are started on a new machine to accept their license. I think you did deploy the tool to a production machine and it was trying to show the consent dialog but nobody did press ok.
They do basically create a registry key on the machine which you can fake if you need a fully automated deployement or you can start in once on the target machine for the user in question.

Further automation with WinDbg

I'm testing an application running on IIS using AppVerifier/WinDbg/cdb. Basically the schema is as follows: when IIS starts cdb attaches to the process and creates a named-pipe, then I use WinDbg to connect to the pipe.
Then I run thousands of test cases against the application and wait until AppVerifier throws something.
Problems/Questions:
For the duration (around 10 hours) of the test, IIS is restarted around thousand times, every time it's restarted WinDbg is shut down and I've to manually re-start the WinDbg. Is there a way to say WinDbg NOT to shut down when the pipe is closed, but retry to connect it?
I've to continuously sit on front of WinDbg and wait for AppVerifier to throw something? Is there a way to say to WinDbg to beep or show a popup when it's stopped by exception?
Thanks.
You can use the sxe command (or other sx* commands) to have WinDbg run a command when an exception is hit. For a trivial example, this prints "Hello, world: " when a module is loaded:
sxe -c ".printf \"Hello, world: \"" ld
You might think to combine this with the .beep command, but this results in a syntax error. I think that might be related to the note in the .beep help that says "This command cannot be used in script files." However, you should be able to use .shell to do something useful.
I haven't tried it, but perhaps it is possible to hack around your reconnection problem using the sx* commands to trap the "process exit" event. Or maybe you could have the cdb instance that is started with IIS notify you when an exception occurs, so that you can then connect to it using WinDbg?

Deliberately crashing an external process under Windows

I would like to synthesise a native code fault. This is so that we can see where in particular some debugging output gets put when that occurrs.
Pskill (from Sys-Internals) causes a graceful exit. DotCrash.exe doesn't seem to be available anymore from Microsoft directly.
Is there any way to externally cause a crash in a process?
I've done this before using windbg by:
Starting the process
Attaching to the process with windbg
Setting a breakpoint on one of my app's functions
Running the app until I hit the breakpoint
In windbg setting a local variable to something that will cause an Access Violation (e.g. set a pointer to 0xFFFFFFFF or muck with the register values)
hit f5 and the app should hopefully crash
If what you want is the equivalent of a coredump, drwtsn32 -p ProcessId generates a dump of the current state of a running process. If you have the appropriate debug symbols you can get valuable information.
HTH.
As Nick mentions, this can easily be done via Debugging Tools for Windows - I'd go one step further though, and use cdb (the command-line WinDbg) to script the whole interaction.
If you need dumps at any desired time, you can use Microsoft's free debug diagnostic tool which has a nice UI to do that or on command line drwtsn32 -p processid as recommended by jrbjazz.
You could try using CreateRemoteThread. Using it correctly isn't easy, but making the other process crash should be pretty easy ;-)
Could you install some kind of hook function, or use something like the detours library?

How can I continue to operate the gdb command console?

Maybe a simple question.
When I attach to a process, I run "continue" to make it continue to run.
Then I want to some other job like "add-symbol-file" with need not interactive with target process, but after the "continue" command, the gdb console will block, so I can not do any action before I break the process.
Is there any way that I can do such thing without suspend the process?
Make sure the console which gdb is running in has keyboard focus, then press CTRL-C. This will usually result in a SIGINT signal to be sent to gdb.
With me, GDB then pauses execution of the program and accepts user commands again.
Should the CTRL-C not work (perhaps different config) try to send the signal manually:
Find out the pid of gdb such as with command top and then send a SIGINT to gdb:
kill -2 pidhere
Until recently you couldn't do what you want, but the newly released
version 7.0 of gdb has what is called a "non-stop" mode, in which the
gdb prompt / console can be used while the program is running.
See http://sourceware.org/gdb/current/onlinedocs/gdb_6.html#SEC47
You may want to study the remote gdb mechanisms a bit for something like that.
For understanding the debugging process more read this short article.

Resources