Post-mortem analysis of Windows Embedded Compact (Windows CE) program - c++

We have an unmanaged C++ application (MFC framework, Windows CE) that closes on us at seemingly random moments.
There is no error message and no C++ exception, it just vanishes.
I presume something bad must have happened and the C run-time or OS decided to kill the program. But I'm not sure where to continue searching.
Question: is it possible to see somewhere in Windows CE why the application terminated in the first place?
Does Windows CE collect basic crash information? Perhaps then one can at least see if it was an Access Violation, an Out of Memory situation, kernel/driver panic or perhaps some other kind of internal or external event that forced the application to close?
On a regular x86 PC one would break out the debugger, application verifier, Windows Error Reporting tools, WinDbg etc. But how to (start) analyze a Windows CE application crash?
What I've tried so far:
Creating global C++ exception handlers at tactical locations in the application. These build and transmit a simple UDP packet containing minimal exception info. these are then viewed on another machine running Wireshark.
Adding the SEH exception compiler switch (/EHa), to be able to catch even those non C++ exceptions, like Access Violation and such.
Connecting the Visual Studio 2008 debugger via TCP/IP with the Smart Device (connects to smart device successfully MSVS says, but debugger doesn't see any remote processes. The Attach to process VS window gives the following error: Unable to Connect to ''.)
Retarget the application so it runs on a regular x86 PC (but then it runs fine, so no "luxury" of debugging the issue there either)
I've tested the exception handler by forcing an Access Violation.
The expected UDP message the arrives at the machine running Wireshark perfectly. But when the real issue occurs, it stays completely silent.
The platform: MS Windows Embedded Compact 7.02 running on a Texas Instruments processor (ARM A8).
The application itself implements a rudimentary VNC viewer. It uses sockets and relies on a third party binary called zlib CE (ZLIBCE.DLL) for decompressing VNC data.
It hasn't been verified if the zlib binary has been built against the exact same compiler (and/or compiler settings).

Settled for a poor man's debugging solution. Now sending application state values to a memory mapped file. The idea is that a specially crafted helper program runs along the main application. This program opens the memory mapped file, displays values it reads from it. And the main program writes to it. If anything fatal happens to the main app, the helper program has the latest state info. Since it is shared memory it doesn't impact performance much. This way found the section of the program where the fault occurs.

Related

Peripheral registers in Qt Creator during debugging

I use Qt Creator to develop embedded application using Bare Metal configuration for STM32. When I debug this application under different IDEs like KIEL uVision, IAR System Workbench or some Eclipse IDE I have special view available where I can see processor specific registers in tree list. Is there something similar for Qt Creator?
I've seen the register view in debug view. Is there possibility to tell it which memory address to show?
EDIT: The application I'm writing is in C and C++. The target is microcontroller based on ARM architecture in this case STM32. There will be no Qt or QML code.
My goal is to use QtCreator as IDE for developing this application. This quite easy as you just configure the compiler (arm-none-eabi-gcc), debugger (arm-none-eabi-gdb) and gdb-server (openocd) in the kit configuration. This allows me to create executable elf file for bare metal target and then flash it to the FLASH memory inside the microcontroller.
All these steps are already done.
However the debugging part gets tricky as part of the memory space is direct hardware configuration and not pure memory. This memory space contains the configuration for the peripherals which allows you to e.g. talk over UART, I2C, ETHERNET, USB or just configure the pins or clock speed.
You need to look at these values and compare them with reference manual and see what each bit does. Currently it is possible to look at the memory map and read it there but Keil uVision, IAR System Workbench and Ecplipse based IDEs have nice plugin where you can see the values exactly as in the reference manual. (see the images)
So my question is if there is some plugin or some way how to view and edit these or if I have to write this plugin myself?
In the latter case I would need to know how to connect to the debugger instance and write commands and read output - mainly read data #address and write data #address. I understand that the gdb uses the MI mode. I tried to connect to gdb from different process but that is not possible so I guess that I'll have to create plugin for Qt Creator. The register description is in file format SVD which is XML with defined structure.
To summarize the last part I look for code that I have to implement in the plugin that will connect me to the running gdb and allow me to send and receive data when it hits breakpoint.
You don't say whether you are debugging C++ code or QML code, so I can't answer with a yes or no. Those register values are useful if you are debugging at the assembly language level (which in itself may or may not be useful).
If you're debugging C++ code, then you can configure your compiler to generate an assembly listing of that code, but you will be debugging at a pretty low level.
If you're debugging QML code, then you would need an assembly listing of the QML engine, which I doubt you will be able to get. More importantly, I suspect that it would be a waste of time to try to debug a declarative language like QML with such a low level procedural debugger. The point of a language like QML is to get you above all that.

Program shuts down silently

There is a multithreaded program that operates simultaneously with a device via COM port based communication and remote (IP) video stream. The program also uses OpenCV library to process the data.
The trouble is that it shuts down without any signals (neither run-time, nor any other errors are caught; log file has no anything useful as well). The most top level application error event handler is set and still there are no any signs of the program crash. It just closes after awhile.
The biggest difficulty is that it works fine on all our PCs for days non-stop. But fails on customers PCs so that testing process is very slow. Customer is in a different country (Asian localization, whilst ours is European), but the program is built with Unicode support.
So far we have got some assumptions about localization issues and antivirus activity... but it gives nothing in result.
The program is written with MinGW 4.4.x C++ and wxWidgets 2.9.3
Any suggestions of the probable origin would be appreciate.
Solved.
The problem was inside OpenCV build 2.3.1, that we use. The function cv::imdecode(...) uses stdio.h`s tempnam() function to generate temporary file during decoding. Under x86 Windows systems this function fails after 32767 new names for temporary file. Under x64 Windows systems it returns some nonsense string, but it still works.
So the solution I came with was to change the way of receiving-decoding images from our device.
Thanks everybody for comments.

Using MATLAB Compiler Runtime on Chinese Windows box

Calling <libname>Initialize() or <libname>InitializeWithHandlers() is hanging when my (non-localized) software is used on a Windows 7 system with Chinese locale. We're using MCR v7.15.
I took a dump of the process and it appears to be a deadlock inside boost thread, if I can trust the stack trace.
I tried running the program with the AppLocale tool, selecting English.
Company let our support contract lapse, and I know from experience that Mathworks won't even review your support case w/o an active contract.
Any suggestions?

How do I write to the VB6 immediate window from C++ based COM object?

I have developed a C++ based COM object to use it in a VB6 application. Now I need to add some logging to catch some of the bugs. I discovered from the answer to 'How to debug COM object in Visual Studio 6.0' question that I can use the OutputDebugString function. But is it possible to write to the VB6 immediate window somehow?
Rather than attempting to write to the immediate window, it would be generally more useful to use DebugView from Sysinternals (now part of Microsoft technet):
DebugView is an application that lets you monitor debug output on your
local system, or any computer on the network that you can reach via
TCP/IP. It is capable of displaying both kernel-mode and Win32 debug
output, so you don't need a debugger to catch the debug output your
applications or device drivers generate, nor do you need to modify
your applications or drivers to use non-standard debug output APIs.
You can use this during development and also in production.
Under Windows 2000, XP, Server 2003 and Vista DebugView will capture:
Win32 OutputDebugString
Kernel-mode DbgPrint
All kernel-mode variants of DbgPrint implemented in Windows XP and
Server 2003
I don't think you can write direct to it but you can use a COM event that just contains a debug.print call.

Lightweight debugging on embedded Linux

I'm developing an application that runs on a small Linux-based SBC (~32MB RAM). Sadly, my app recently became too large to run under GDB anymore. Does anyone know of any good, lightweight debugging methods that I can use in embedded Linux? Even being able to view a thread's stack trace would be extremely helpful.
I should mention that this application is written in C++ and runs multiple threads, so gdbserver is a no-go as it doesn't work with multithreaded apps.
Thanks in advance,
Maha
gdbserver definitely works with multi-threaded applications, I'm working on an embedded project right now with >25 threads and we use gdbserver all the time.
info threads
lists all the threads in the system
thread <thread number from info threads>
switches to that thread of execution.
thread apply XXX <command>
Runs on the thread designated by XXX, which can also be 'all'. So if you want the back trace from all running threads do
thread apply all bt
Once you're in the execution flow of a given threads all your typical commands work as they would in a single threaded process.
I've heard of people doing hacks like running the application in an emulator like QEMU and then running GDB (or things like valgrind) on that. It sounds painful, but if it works....
Would you get anywhere with libunwind (to get stack traces) and printf-style logging?
Serial port printing is the most light weight I can think of ~~~
Easily seen in a Host PC, and simple and light weight code inside your app~~
If you do not have a serial port, once we used an GPIO port and simulated a serial port using it. It worked perfectly well, but was a bit slow :-( ~~~
Is there a reason why you have built your own debugger? I am developing a Linux system using an ARM processor (AT91SAM926x) and we are using both compiler and debugger from CodeSourcery. I do not think that they have released a version with GDB 7 yet but I am debugging multithreaded C++ applications using the gdbserver tool without any problems.
Gdbserver does indeed work with multithreaded applications. However you do need to compile a cross target debugger for your host to get it to work with your target gdb.
See this article for a detailed description of how to do it:
Remote cross-target debugging with GDB and GDBserver