Archive for the ‘Notes on Developers Guide to Debugging’ Category

Reading Notebook: 23-Apr-09

Friday, April 24th, 2009

Comments in italics are mine and express my own views, thoughts and opinions

Developer’s Guide to Debugging by M. Wloka, et al.:

debugging as reverse engineering (p. 169)

two camps of source commenters (pp. 169 - 170) - I personally tend to belong to the camp of writers of self-documentary code 

workaround turns a bug once the underlying cause is fixed (p. 171)

consistent coding style (p. 171) - I fully agree and when I fix a bug I adopt whatever coding style is used in the code 

naming style (pp. 171 -172) - Here I would say that MS prefers its own styles (Hungarian notation) instead of C++ standard library and I prefer to use the former when writing programs on Windows except maybe short illustrative examples for language features and exception processing. And I don’t like underscores as name separators.

spreading the code (p. 172) - I even tend to split complex logical expressions into several lines of code

avoiding macros (pp. 173 - 178) - regarding macros in C/C++: an idea came to me for the need to have a program or WinDbg extension that gives you macro text for any given number. For example, a window message text, an status or error value text, and so on. This would be handy for raw debugging or postmortem crash dump analysis

debugging preprocessor output via a compiler switch (pp. 176 - 177)

external preprocessors like m4 (pp. 177 - 178) - I’m considering to use an external preprocessor for the Riemann programming language I invented.

custom debugging functions in code to call from a debugger (pp. 179 - 181)

writing analysis functions (p. 180) - I used this when writing a word processor long time ago to check the consistency of internal structures: http://www.dumpanalysis.org/blog/index.php/2006/12/16/real-programmers-no-impossible-code/

coupling tracing with postmortem dumps (pp. 181 - 182) - See also Historical Information and Execution Residue patterns: http://www.dumpanalysis.org/blog/index.php/2007/11/06/crash-dump-analysis-patterns-part-34/ and http://www.dumpanalysis.org/blog/index.php/2008/04/29/crash-dump-analysis-patterns-part-60/. Also in Citrix environments we use CDF logging which can be circular coupled with memory dump analysis

static checking as an aid in debugging (pp. 183 - 190) - I recall that when I was working at Programming Research Ltd. on their static QA C++ checker and particular STL usage checks we used it against our own C++ code and I confess that there was no need to use GDB. In a few times when program crashed I used logging to narrow down the statement

cleanup session to eliminate all compiler warning (p. 184) - I hate compiler warnings too and change code until they disappear

Finished this book!!! Edited notes also appear in Software Engineering Notebooks, Volume 1 (ISBN: 978-1906717148) later this year

Advanced Windows Debugging by M. Hewardt and D. Pravat:

Concurrent Programming on Windows by J. Duffy:

Software Factories by J. Greenfield, et. al.:

Software Engineering Foundations: A Software Science Perspective, by Y. Wang:

Didn’t have time today - resume reading next week

- Dmitry Vostokov @ SoftwareGeneralist.com -

Reading Notebook: 22-Apr-09

Wednesday, April 22nd, 2009

Comments in italics are mine and express my own views, thoughts and opinions

Developer’s Guide to Debugging by M. Wloka, et al.:

function arguments from stack (pp. 163 - 165) - kv, kP or kp WinDbg; also .frame and dv commands 

p sizeof (int) in GDB (p. 163) - equivalent to ?? sizeof (int) in WinDbg

x/s in GDB (p. 164) - da command in WinDbg; du for UNICODE

info reg in GDB (p. 164) - r command in WinDbg

safe register association with arguments at the beginning of a function (p. 164) - See my Optimized Code pattern: http://www.dumpanalysis.org/blog/index.php/2006/12/15/crash-dump-analysis-patterns-part-5/

The notion of an argument anchor to search for other arguments on a raw stack (p. 164) - very useful technique I used many times

user-defined data types (p. 165) - in the absence of symbols for dt command it is indeed tedious to find field correspondence between headers and binaries  

approximate source code line (pp. 165 - 166) - ln command and, of course, disassembling u, ub and uf WinDbg commands. Beware of OMAP optimization though: http://www.dumpanalysis.org/blog/index.php/2007/04/20/crash-dump-analysis-patterns-part-5b/

stepping through assembly code set step 1, nexti in GDB (pp. 166 - 167) - l-t to switch to assembly mode from source mode and then t or ta (trace to address) WinDbg commands

Advanced Windows Debugging by M. Hewardt and D. Pravat:

Concurrent Programming on Windows by J. Duffy:

Software Factories by J. Greenfield, et. al.:

Software Engineering Foundations: A Software Science Perspective, by Y. Wang:

Didn’t have time today - resume reading tomorrow

- Dmitry Vostokov @ SoftwareGeneralist.com -

Reading Notebook: 21-Apr-09

Tuesday, April 21st, 2009

Comments in italics are mine and express my own views, thoughts and opinions

Developer’s Guide to Debugging by M. Wloka, et al.:

manipulating program code and data in a debugger instead of recompilation (pp. 153 - 161)

print GDB command (p. 154) - dv WinDbg command and also various variants of d command 

set var GDB command (p. 154 ) - e command variations in WinDbg; also r command to change registers or $retreg

call GDB command (p. 154) - .call command in WinDbg

getting out of functions ot skipping code (p. 154) - in WinDbg you can assemble nop, jump or ret opcodes for this purpose; also consider changing $ip

whatis GDB command (p. 159) - x, dt and dv WinDbg commands

x GDB command (p. 159) - d command variants in WinDbg

debugging without symbols (p. 161) - On Windows and with Visual C++ it is easy to handle as symbol files (.PDB) can be kept separately and even accessible from customer environments via public symbol servers

Advanced Windows Debugging by M. Hewardt and D. Pravat:

Concurrent Programming on Windows by J. Duffy:

Software Factories by J. Greenfield, et. al.:

Software Engineering Foundations: A Software Science Perspective, by Y. Wang:

Didn’t have time today - resume reading tomorrow

- Dmitry Vostokov @ SoftwareGeneralist.com -

Reading Notebook: 20-Apr-09

Monday, April 20th, 2009

Comments in italics are mine and express my own views, thoughts and opinions

Developer’s Guide to Debugging by M. Wloka, et al.:

watchpoints (data breakpoints), watch and *watch GDB commands (pp. 143 -144) - ba in WinDbg

signals (pp. 144 - 146) - APC on Windows?  Asynchronous exceptions on Windows?

exceptions in C++, catch and throw GDB commands (pp. 147 - 148) - A hint for Visual C++. You need to specify exception model via /EH switch   

reading stack traces, where GDB command (pp. 148 - 153) - k command variants in WinDbg

frames reported as ?? in GDB (pp. 149 - 150) - In WinDbg we have similar cases when PDB files are not available, module code is not present or simply basic frame based linking doesn’t work and WinDbg is not able to reconstruct stack trace. Here we have a message: “WARNING: Frame IP not in any known module. Following frames may be wrong.”

Broken stack traces (pp. 151 - 152) - Here is my case study about manual stack trace reconstruction using WinDbg: http://www.dumpanalysis.org/blog/index.php/2007/07/25/reconstructing-stack-trace-manually/

core dump files (pp. 152 - 153) - For Windows there are plenty of possibilities to get crash dump files. Look for articles in “The Origin of Crash Dumps” chapters in Memory Dump Analysis Anthology, Volume 1 and Memory Dump Analysis Anthology, Volume 2. WinDbg is the standard tool to analyze crash dumps in technical support. 

Advanced Windows Debugging by M. Hewardt and D. Pravat:

Concurrent Programming on Windows by J. Duffy:

Software Factories by J. Greenfield, et. al.:

Software Engineering Foundations: A Software Science Perspective, by Y. Wang:

Didn’t have time today - resume reading tomorrow

- Dmitry Vostokov @ SoftwareGeneralist.com -

Reading Notebook: 15-Apr-09

Wednesday, April 15th, 2009

Resuming reading notebook and plan to fill it at least 3-4 times per week

Comments in italics are mine and express my own views, thoughts and opinions

Developer’s Guide to Debugging by M. Wloka, et al.:

Implicit or hidden function calls in high level languages, step-into command, GDB step (pp. 133 - 135) - t command in WinDbg

step-out command to bypass stepping through implicit functions, GDB finish command (p. 136) - gu command in WinDbg

temporary breakpoint in GDB, tbreak (p. 136) - also .step_filter in WinDbg to create the list of function to skip

conditional breakpoints and breakpoint commands (pp. 138 -139) - bp and ba commands in WinDbg have an additional parameter: command string; Also bp “J” and bp “.if” conditional variants in WinDbg

print strcmp(…) and $$0 in GDB (p. 139) - I think in WinDbg this can be done via .call and $callret

static constructors and initializers (pp. 140 - 143)

technique: slowing the program to have time to attach the debugger (p. 142)

Advanced Windows Debugging by M. Hewardt and D. Pravat:

.dbgdbg command (p. 368)

technique: using local kernel debugger when user debugger extension fails (p, 375)

Concurrent Programming on Windows by J. Duffy:

A thread may already begin or even finish by the time CreateThread returns (p. 89)

thread pseudo-handle from GetCurrentThread == -2 (p. 94)

thread handle from thread id - OpenThread (p. 95)

use CRT function only in threads created by _beginthread(ex) (p. 96)

_beginthread closes handle automatically by return of start routine (p. 97)

Software Factories by J. Greenfield, et. al.:

EAI to solve the problem of data flow and transformation between applications on different servers (p. 21)

Building applications from business process perspective (p. 22)

DCOM and CORBA are tightly coupled to component implementations (p. 23)

service-oriented architecture (SOA): loosely coupled coarse grained components, message interaction, protocol sequencing defined by contracts and negotiated constraints (SLA, service level agreements) (p. 25)

BPMS (business process management system) as logical analog to DBMS (pp. 25 - 26)

pi-calculus as theoretical platform for BPMS (p. 25)

CRM subprocesses: campaigns, sales force and leads, customer management, customer service and self-service (pp. 28 - 29)

Portals as encapsulation of user interaction (p. 30) - an idea of tool portals for troubleshooting; Also each troubleshooting domain is implemented as a troubleshooting process or service that encapsulates troubleshooting logic and required data access; troubleshooting facades working with older troubleshooting tools

Software Engineering Foundations: A Software Science Perspective, by Y. Wang:

Didn’t have time today - resume reading tomorrow

- Dmitry Vostokov @ SoftwareGeneralist.com -

Reading Notebook: 16-Feb-09

Monday, February 16th, 2009

Comments in italics are mine and express my own views, thoughts and opinions

Developer’s Guide to Debugging by M. Wloka, et al.:

DLL-specifc problems (pp. 122 -127) - For Windows, I’ve identified 2 patterns so far: http://www.dumpanalysis.org/blog/index.php/2008/04/22/crash-dump-analysis-patterns-part-59/ and http://www.dumpanalysis.org/blog/index.php/2008/06/12/crash-dump-analysis-patterns-part-59b/

-fPIC flag for GCC to generate position independent code for dynamic linking and -shared flag to generate .so files (p. 123)

ldd utility on UNIX to find required .so files (p. 124) - On Windows it can be Dependency Walker (depends.exe)

Incorrect search order problems (p. 124) - See also my pattern for Windows: http://www.dumpanalysis.org/blog/index.php/2008/06/19/crash-dump-analysis-patterns-part-64/

Analyzing loader issues, LD_DEBUG on UNIX (pp. 125 - 126) - On Windows it can be loader snap in option in gflags.exe and !dlls WinDbg command

shared library GDB command (p. 126) - corresponding WinDbg command lmv

break GDB command (p. 126) - corresponding b* commands in WinDbg

pending breakpoints (pp. 126 - 127) - corresponding deferred or unresolved breakpoints in WinDbg (bu command)

ptype and info function commands in GDB to list class methods and overloaded functions (pp. 130 and 131)

breakpoints in C++ templates, function signatures for instantiated templates vs. source code lines (pp. 131 - 132) - I need to check this with WinDbg

info breakpoints GDB command (p. 132) - corresponding WinDbg commands are bl and .bpcmds

Advanced Windows Debugging by M. Hewardt and D. Pravat:

Implicit CoInitializeSecurity with EOAC_APPID (p. 365)

ole32!g* variables (p. 366)

Client callback interfaces make gives a client a server role (p. 367)

DCOM failure logging registry keys (p. 367)

Concurrent Programming on Windows by J. Duffy:

Software Factories by J. Greenfield, et. al.:

Software Engineering Foundations: A Software Science Perspective, by Y. Wang:

Stiil busy to read last 3 books. Hope to resume them tomorrow.

- Dmitry Vostokov @ SoftwareGeneralist.com -

Reading Notebook: 11-Feb-09

Wednesday, February 11th, 2009

Comments in italics are mine and express my own views, thoughts and opinions

Developer’s Guide to Debugging by M. Wloka, et al.:

Linking order (pp. 113 - 114) - I need to check this with MS linker, how many passes does it have

Symbol clash as undetected multiple definitions (pp. 117 - 118) - I need to check this with MS linker

Symbol localization (suppressing exports) EDITBIN and LIB on Windows (p. 118) - Never used EDITBIN before. Will try

The possibility of crash due to linker mismatch or error (p. 120)

How to determine a compiler version from an object or library file? (pp. 120 - 122) - It looks like .obj files compiled by MS compiler contain all compilation options and the following string, for example: -compiler:”c:\Program Files (x86)\Microsoft Visual Studio 8\VC\bin\c2.dll”

Advanced Windows Debugging by M. Hewardt and D. Pravat:

Breaking the code path technique: freezing processes one by one and checking if this freezes the client (p. 355)

AccessCheck in RPCSS, machine access check -> machine launch check -> component-specific check for DCOM (pp. 357 - 361)

RPCSS service -> DcomLaunch service (p. 362)

Concurrent Programming on Windows by J. Duffy:

Software Factories by J. Greenfield, et. al.:

Software Engineering Foundations: A Software Science Perspective, by Y. Wang:

Didn’t have time today. Will resume notebook on Friday.

- Dmitry Vostokov @ SoftwareGeneralist.com -

Reading Notebook: 09-Feb-09

Monday, February 9th, 2009

Comments in italics are mine and express my own views, thoughts and opinions

Developer’s Guide to Debugging by M. Wloka, et al.:

An application as a set of processes (p. 103)

strace (Linux) and truss (Solaris) to trace OS calls (pp. 104 - 106) - On Windows we can trace API while debugging using WinDbg extensions: http://www.dumpanalysis.org/blog/index.php/2007/01/03/tracing-win32-api-while-debugging-a-process/. Process Monitor can also be used to trace API subsets like File and Registry I/O.

Compiler bugs (pp. 106 - 107)

Debugger and compiler incompatibilities (p. 107)

Link-time bugs (Chapter 9)

Missing symbols (pp. 112 - 113) - On Windows search strategies like Explorer Search and dumpbin can be useful for dynamic linking errors

Advanced Windows Debugging by M. Hewardt and D. Pravat:

The importance of lazy initialization and associated impersonation bugs (pp. 347 - 354)

Concurrent Programming on Windows by J. Duffy:

.NET programs are multithreaded from the start (gc runs on a separate thread) (p. 79) - We can see this in WinDbg when attaching it to a .NET app container

Thread as a virtual processor metaphor (p. 80)

Thread as an execution context (p. 81)

Non-local transfer of control; context switch, exception handling, hardware interrupt (borrows kernel stack), DPC and APC (pp. 84 - 85)

DPC and APC run in the context of the current thread (p. 85)

The differences of CLR (managed) threads: just additional CLR information is stored on per OS thread basis (p. 86)

Explicit threading: explicit thread creation (p. 87) with thread pool alternative (p.88)

Software Factories by J. Greenfield, et. al.:

Failure of enterprise data modeling during terminal era of 70s - 80s (p. 13)

Bifurcation of of software into personal and enterprise with the advent of PCs (pp. 15 - 16)

The notion of the phenomenon of cheaper products eventually displacing market leaders after improvement over time (p. 16)

Thick client: business rules on both tiers (p. 17)

The growth of packaged application industry and outsourcing after client-server era (pp. 18 - 21)

Software Engineering Foundations: A Software Science Perspective, by Y. Wang:

SE principles to counter SE constraints (cognitive, organizational and resource) (p. 2)

Software as a unique abstract structure (p. 7)

The notion of the intelligent behavioural metaphor (p. 7)

Inductive math-based methodology of theoretical software problems vs. deductive experiment-driven for empirical problems: both must be used for SE problems (1st Law of SE)  (p. 8)

The need for mathematical modeling of software system architecture and software behaviours (p. 9)

- Dmitry Vostokov @ SoftwareGeneralist.com -

Reading Notebook: 06-Feb-09

Friday, February 6th, 2009

Resumed my reading notebook today after more than two week break caused by finishing my Windows Debugging book.

Comments in italics are mine and express my own views, thoughts and opinions

Developer’s Guide to Debugging by M. Wloka, et al.:

Deadlock roots (circular locking and protocol mismatches in produce-consumer scenarious (p. 93)

info thread command in GDB (0. 95), thread N command to switch current thread, info stack command - In WinDbg we use ~*kv in process dumps and !process 0 ff in kernel and complete kernel dumps. Beware of WOW64 though:
http://www.dumpanalysis.org/blog/index.php/2007/01/26/note-32-bit-stack-from-64-bit-dump/ and http://www.dumpanalysis.org/blog/index.php/2009/02/06/32-bit-stack-traces-from-x64-complete-dumps/

Threading analysis tools: Intel Thread Checker and Helgrind (pp. 96 - 98) 

Environment dependency as root cause for some problems (pp. 101 - 103)

Advanced Windows Debugging by M. Hewardt and D. Pravat:

The importance of system boundaries (pp. 338 - 340)

Logical error representations by subsystems (p. 341) 

Security descriptor for debugger created thread can have different DACL (pp. 346 - 347)

Security chapter is awesome - sheds light on what described in other Win32 security books

Concurrent Programming on Windows by J. Duffy:

Software Factories by J. Greenfield, et. al.:

Software Engineering Foundations: A Software Science Perspective, by Y. Wang:

I resume reading these books next Monday

- Dmitry Vostokov @ SoftwareGeneralist.com -

Reading Notebook: 22-Jan-09

Thursday, January 22nd, 2009

Comments in italics are mine and express my own views, thoughts and opinions

Developer’s Guide to Debugging by M. Wloka, et al.:

VTune profiling (pp. 82 - 83) - there are also Visual Studio profiler http://msdn.microsoft.com/en-us/magazine/cc337887.aspx, Visual Studio Team System profiling tools and Windows kernel profiler kernrate

TBB, OpenMP, MPI and Google MapReduce (p. 87) - I have a book about Intel TBB *Threading Building Blocks”, should read or browse it soon

Mimic the scheduling (p. 90) - One technique I found useful is when you suspect two separate racing functions we can patch function prolog with a return to see if the problem is gone

Using log file to localize race conditions (p. 91 - 93) - In Citrix we use CDF tracing based on ETW (http://msdn.microsoft.com/en-us/library/aa468736.aspx) as application-, service- and system-wide logging mechanism. It records TID and PID for every trace statement. All debug statements are actually written in a production environment if we choose to record certain or all categories of them:
http://support.citrix.com/article/ctx117426

stderr should be unbuffered (p. 91)

debugger tracepoints (p. 93) - stop, record data, resume - similar techniques exist in WinDbg/CDB/KD family of debuggers

Advanced Windows Debugging by M. Hewardt and D. Pravat:

Concurrent Programming on Windows by J. Duffy:

Software Factories by J. Greenfield, et. al.:

Software Engineering Foundations: A Software Science Perspective, by Y. Wang:

Didn’t have time today to read these 3 books because of the work on my next book ”Windows Debugging: Practical Foundations”

- Dmitry Vostokov @ SoftwareGeneralist.com -