From MPLAB 8.92 to MPLAB X 5.25: how do I programmatically halt the simulator now? - pic

I wrote some test code in PIC assembly language that I have no intention to run on the actual PIC MCU, rather it is meant to generate the trace files so that they can be analyzed later with a separate tool. So, I needed a way to permanently halt the simulator in specific code points without manually setting the breakpoints there. This way I could terminate trace collection from code.
Back in the MPLAB 8.92 I used this simple trick to accomplish that: "call $" command. This instruction simply calls itself, quickly overflowing the stack and in MPLAB 8.92 this was halting the simulator with CORE-E0001 message. Mission accomplished!
However, when I migrated to MPLAB X 5.25, I have discovered that the simulator does not halt anymore using this trick. It does not halt even if I go to the project settings and specify that simulator should break on all types of warning messages.
So, what am I doing wrong? What it the best working way to halt the simulator with an MCU code in MPLAB X? Please do not suggest using an explicit breakpoint, this is just not practicable, I would literally need to set hundreds of breakpoints in tens of projects.

In MPLAB go to Project Properties. In Categories tree: select Simulator the Options for Simulator are now visible. Under Options categories select Warning Messages Break Options and press on Unlock button.
Let say that you wont that your simulations stops on Watchdog Timer reset event. Find on list W0004-CORE: Watchdog Timer has caused a Reset. and change Report option to Break.
Press Apply button.
Now the program simulation will stops on every Watchdog Timer reset event.
PS: I'm using MPLAB v5.35. For break at stack overflow use option W0012-CORE: Device Resets on stack overflow.

Related

Watch variables disappear in VSCode when debugging an STM32 project

I've been trying to debug an STM32 project in VSCode. I'm able to start the debugger and add variables to the watch list. However, the moment I run the code, the watch variables disappear. Is there a way to view them in real-time as the code is running? Here is a short video of what happens.

Windbg break-in takes very long time

I want to capture a stacktrace of an application which sometimes stops responding for few minutes.
When the application stops responding, the windows desktop also stops responding to mouse clicks, although some other already running applications are working fine at that time (for example windbg works fine, ProcessExplorer refreshes its screen, but does not respond to mouse events).
While the application is non responsive, it is actually taking about 80% of one CPU core. That is why I would like to get a stacktrace.
The misbehaving application usually takes about 2-3 minutes to do its strange job or if Ctrl+Esc is pressed it becomes responsive immediately (and the start menu opens of course...)
I have WinDbg attached to the misbehaving application and when I issue the Break command, the break-in does not happen until the application starts to respond again.
From what I understand the break-in actually creates a remote thread which pretty soon calls DbgBreakPoint.
What could be preventing debugger's thread from executing?
EDIT:
First of all thanks for your help!
I was also thinking that this might be caused by a bad device driver or something that installs a system wide hook somewhere.
I was thinking to enable kernel debugging and get a stack trace from the kernel for the offending thread or enable manual bluescreen trigger to produce a dump and look at that afterwards.
Process Explorer and Process Monitor does not reveal anything interesting. They also become unusable when the bug is triggered (updating their windows but not responsive to mouse or keyboard).
EDIT2:
Background info:
App uses QT, OpenGL and also DirectSound and runs on Windows 7 SP1 x64
I am currently suspecting something with the graphics part.
The strange thing is that if a system-wide lock is taken (like GDI Lock), this would prevent drawing of other Windows, but that does not happen. WinDbg on same machine works fine. ProcessExplorer updates but does not receive mouse clicks, Desktop updates but no mouse clicks.
I currently have a kernel debugger attached...
EDIT3
ETW was most useful for debugging. It turns out that Qt's main event processing loop goes crazy. PeekMessage and MsgWaitForMultipleObjectsEx (with 0 timeout) gets called in a tight loop. That is where the high CPU usage comes from.
It looks like the App is generating/getting loads of messages at that time. But it is not easy to see what the messages are (or I don't know how to access function parameters in ETW). Using a debugger also does not help much but, with a breakpoint in the QT's event loop leads me to believe that WM_TIMER messages are the culprit.
Given that the desktop also misbehaves during this time, it sounds like your app isn't necessarily misbehaving but merely aggravating a bug elsewhere (e.g., in a device driver or some crummy anti-malware code that has injected itself into other processes). Stack traces from your app may or may not be very revealing.
If the problem is easily reproducible, I'd set a breakpoint somewhere in the "middle" of the app and see if the problem happens before or after that. Then move the breakpoint until you find the last instruction your app executes before things go bonkers. Figuring out what your app does that triggers this behavior may give a clue as what's going on.
Another option is to try using some system-wide debugging tools. First, I'd peak in the Event Viewer to see if there are suspicious error or warning events posting in proximity to the moment the machine goes haywire. Then I'd try a tool like Sysinternal's Process Monitor or Process Explorer to get a better view of what's happening. You might also try ETW to capture a system-wide trace of what's happening on the system that you can study after the fact. (ETW can be hard to use, so check out Bruce Dawson's UIforETW.)
Use ETW to find the cause. Install the Windows Performance Toolkit (part of the Win10 v1511 SDK: https://go.microsoft.com/fwlink/p/?LinkID=698771 which is the last version that works in Win7), run WPRUI.exe, select CPU Usage and click on Start.
After you captured the hang, click on Save. Wait until WPRUI is finished, open the ETL in WPA, setup and load debug symbols in WPA.
Drag & Drop the CPU Usage (Precise) graph to analyse pane and look for WAIT (µs) max for your process to see that long hang and expand the stack to see where it happens.

directx 11 c++ application in vs 2012 -- full screen crashes after running for a while

Win7 Directx 11 with VS 2012 -- When I let my app run in full screen on my development computer, eventually, the program exits full screen back to windowed, all by itself, and pops up a dialog telling me windows resources are running low. The dialog tells me something about turning off interactive themes or something to that end. When I run the program in release mode on one of our client machines, the app runs fine, does everything it should, but after a while, instead of popping up the dialog about windows resources, I get an exception window with exception 0x40000015 as the error. This only happens if I am in full screen, windowed, it never crashes. Event Viewer shows nothing at all about the crash. Any thoughts?
Thanks in advance. Basically what my app is, is a wrapper graphics library. When it says I am using all the resources, my resource monitor shows that I never went above 20% of memory and the cpu never went above 14%. The 0x40000015 error number is rather general and doesn't exactly point me in any real direction.
This is not related to trying to exit an app in full screen, as that I have the code required to prevent the exception related to that problem.
R
It turned out to be a component issue on the target platform. The ReportLiveDeviceObjects info was helpful and will continue to help down the line.

xamarin studio stops debugging

I'm using xamarin studio and monotouch for developing iphone applications. When I set break points on my code and start debugging with the xamarin studio, the debugger breaks the codes on the break point correctly, but the problem is that when I trace the codes with debugger after some seconds ( maybe 30-40 sec) the debugger stops debugging, just like a crash. What should I do?
EDIT
I noticed that it is not because of the break point. Whenever I do not work with the phone after a few seconds the debugger disconnect and stop debugging. Is this really a bug? I think maybe there is a setting that if I change it then the issue will be fix.
Isn't this done by the iOS operating system??? doesn't it only give you ~30 seconds to return from the first event otherwise it kills the application process ? So if you sit in the debugger then it will kill that too?
If it's a bug, verify if there is a newer release and update you copy.
Otherwise, report it to the software providers for a solution.

Xcode debugger hangs entire system

I am trying to resolve a Bonjour network service, and there is a bug in my netServiceDidResolveAddress: handler, a null reference exception. When I run the app, it hits the bug, and Xcode drops into the debugger, showing the offending line and "Thread 1: Program received signal: EXC_BAD_ACCESS". All fine.
But when it does this, my entire system hangs. Not just Xcode, but the entire OS X UI is frozen. The mouse moves, and music and other background tasks seem to continue, but the UI is completely unresponsive. The only way out is a hard reboot of the entire system. Yikes.
I do a fair amount of low-level programming and this is happening more often than I'd like. I've seen the other questions here about Xcode itself freezing on breakpoints and exceptions but nothing about a full system hang.
Has anyone else encountered this? Any suggestions on recovering (or avoiding the issue entirely)?

Resources