Docsity

Debugging Pointers and Dynamic Data Structures: Common Problems and Solutions, Slides of Business Administration

Toggle sidebar
bg1
Execution Flow
•Step Into -Execute code, step into a
function if one is called
•Step Out -Continue execution until N-1’st
region of stack frame reached
•Step Over -Execute code, execute any
functions that are called without stopping.
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Debugging Pointers and Dynamic Data Structures: Common Problems and Solutions and more Slides Business Administration in PDF only on Docsity!

Execution Flow

  • Step Into - Execute code, step into a

function if one is called

  • Step Out - Continue execution until N-1’st

region of stack frame reached

  • Step Over - Execute code, execute any

functions that are called without stopping.

Debugging Pointer and Dynamic

Data Structure Problems

  • Pointers and explicitly allocated dynamic

data structures are a central feature in many

popular procedural and object-oriented

languages

  • Great power - especially in extreme cases

(eg C/C++)

  • Can be very painful to debug

Pointers to Bogus Memory

  • Uninitialized pointers
  • Failing to check memory allocation errors
  • Using stomped pointers corrupted by previous memory operations
  • Reminder: Bogus memory access does not necessarily trigger a memory protection fault
  • Remedy: Add data type info to dynamic data structures
  • Special Case: Indices above/below array space
  • Remedy: index checks Docsity.com

Corrupt Data Structure Segments

  • Incorrect Adds/Deletes in trees/lists/etc.
  • Stomped pointer values from previous memory operations
  • Remedy 1: Add type info to dynamic data structures
  • Remedy 2: Create routines to check integrity of data structures
  • Remedy 3: Flag deleted memory areas

Accessing Elements of Wrong

Type

  • Access data element of type x, but think you are accessing one of type y
  • Can be a source of frequent headaches depending on application/implementation
  • Remedy: Include type info in memory allocations

Accessing Data After Freeing It

  • Can be a source of many headaches
  • Remedy 1: Include freed flag in memory (not a guaranteed solution
  • Remedy 2: Create list of “freed” memory, but do not deallocate it. Check list when dereferencing pointers (very expensive in both time and space)
  • Big Brother Problem: Accessing data structure after adding it to a “free” list for quick future reuse
  • Remedy: Remedy 1 plus a use counter (also not a guaranteed solution) Docsity.com

Debugging Multitasking

Programs

  • Multiple process/multi-threaded code ubiquitous in modern programs
  • Many debuggers will work with these programs, but it is not always elegant or easy.
  • Fallback method: Put new processes to sleep and then attach a debugger to them before they awake.
  • Better solution: Read debugger documentation, find better one if it is weak in this area.

A Few Tips

  • Pointers and multithreading together can be

extremely difficult to debug

  • Try to debug parts by themselves before

tackling combined system

  • Analogous strategies to those used in

pointer debugging can be a big help

  • Thread/process timing an important concern

in the debugging process