The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,738 other followers

Archive for the ‘Debugging’ Category

How to debug small programs

Posted by jpluimers on 2019/10/17

As a follow up of SSCCE, MWE and MCVE are basically the same: provide code people can use to reproduce a problem, I found [WayBackHow to debug small programs which is starts as

One of the most frequent categories of bad questions I see on StackOverflow is: I wrote this program for my assignment and it doesn’t work. [20 lines of code]. And… that’s it.

Then it goes on how to debug those pieces of code, trim them into an SSCCE/MWE/MCVW to form the base of a question which you can ask on StackOverflow/SuperUser/ServerFault/StackExchange, forum, group/community or even your co-worker.

The really cool thing about the techniques used there are that they also apply to bigger pieces of code, heck even large code bases.

They force you to trim down your problem in to manageable pieces that are easy to explain and write concise documentation and tests around them to assist you in the process.

Below are the steps in a short list. Be sure to read the original article How to debug small programs | Fabulous adventures in coding after going through the list.

  1. Turn on compiler warnings, inspect all of them, resolve or explain them
  2. Rubber duck to an imaginary person or even a live one explaining each part in simple terms
  3. If the bug is still there, break up the code into pieces
  4. Write technical specifications for all the pieces
  5. Verify the pieces against the specifications, for instance by adding pre- and postconditions to them
  6. Add assertions in the pieces for all the specifications
  7. Write test cases for the pieces
  8. Write down on paper the expected behaviour for all the lines of code
  9. Use a debugger to step through all the lines of code and verify the expected behaviour you wrote down
  10. While debugging, listen to all your doubts (gut feeling is a good thing!)

This sounds like a lot of work. It is. All good programming is.

If you apply these before writing any logic code, then your life becomes easier because you will spot bugs sooner:

  • specification
  • test cases
  • preconditions
  • postconditions
  • assertions

Does this again sound like a lot of work?

Then remember: taking a shortcut will make the actual work longer. The reason is that hunting for bugs is a tedious and time consuming process scaling very badly with complexity.

–jeroen

Posted in Conference Topics, Conferences, Debugging, Development, Event, Software Development | Leave a Comment »

It’s a blong, blong, blong road…: ‘What if?’ scenario analysis in the CPU window

Posted by jpluimers on 2019/07/31

Patching code at debug-time: [WayBackIt’s a blong, blong, blong road…: ‘What if?’ scenario analysis in the CPU window.

Remember:

  • There are dragons
  • Patching too many bytes will kill a kitten and likely your application.
  • Bytes in memory might not be what they seem, especially when having breakpoints (and the debugger frantically trying to set/remove $CC bytes for the INT 3 instruction)

I’ve done this for 20+ years and usually use the $90 byte (NOP instruction) though your experience may be different.

–jeroen

 

Posted in Debugging, Delphi, Development, Pascal, Software Development, Turbo Pascal | Leave a Comment »

Laptop fan profiling, and debugging them – related to Profiling | CommitStrip

Posted by jpluimers on 2019/07/23

A while back, I posted the “profiling” CommitStrip on[WayBack] Profiling – Jeroen Wiert Pluimers – Google+. Boy how did I not know that within a week, I bumped into a “laptop fan profiling” artefact.

A coworker noticed, that when starting a thread based equivalent of [WayBack] TTimer Class (which cannot be used in services as it depends on the VCL), then sometimes the laptop fans would spin up.

What basically happened was that for certain combinations of Enabled and Interval the Execute would loop burning 100% of one CPU core.

With 3 or more – sometimes 2 – of these threads active on a 4+4 core (4 are hyper-threaded), the processor fan would start to spin like madness.

Finding the solution was somewhat easy too:

  • Process Explorer would show the thread IDs burning the most CPU cycles
  • Delphi shows the Thread IDs in the Thread Status pane (if they are named, the ID is at the end of the name in parenthesis)
  • At around Delphi 2010, you can Freeze or Thaw threads. This allows you to debug only a single thread by freezing all others.

Focussing on one thread, allowed a close inspection of the loop, quickly finding the actual cause and repairing it.

TTimer Thread

A similar and better class is at [WayBack] multithreading – TTimerThread – Threaded timer class – Code Review Stack Exchange, based on [WayBack] timer – Using VCL TTimer in Delphi console application – Stack Overflow.

Read the rest of this entry »

Posted in Conference Topics, Conferences, Debugging, Delphi, Development, Event, Fun, Multi-Threading / Concurrency, Profiling-Performance-Measurement, Software Development | Leave a Comment »

gdbgui – browser based debugger for C, C++, go, rust, Fortran. Modern gdb frontend.

Posted by jpluimers on 2019/03/05

[WayBack] gdbgui – browser based debugger for C, C++, go, rust, Fortran. Modern gdb frontend.: gdbgui (gnu debugger graphical user interface)

Via: [WayBack] Browser-based debugger for C, C++, go, rust, and more – written in Python with Flask. https://github.com/cs01/gdbgui Easy installation via PyPI: pip i… – Joe C. Hecht – Google+

–jeroen

Posted in C, C++, Debugging, Development, Fortran, GDB, Go (golang), Python, Scripting, Software Development | Leave a Comment »

Hi there. Is it possible to get RTTI information for IDE “built-in” classes …

Posted by jpluimers on 2018/12/04

For my link archive: [WayBack] Hi there.Is it possible to get RTTI information for IDE “built-in” classes with an OTA Wizard?Let’s say I create a TRttiContext object in my wizard…. – Fl Ko – Google+

Here is an IDE explorer that helps: [WayBack] GitHub – DGH2112/Delphi-IDE-Explorer: A RAD Studio IDE wizard / expert / plugin that allows you to browser the internal fields, methods, properties and events of the IDE.

–jeroen

Posted in Debugging, Delphi, Development, Software Development | Leave a Comment »

 
%d bloggers like this: