Skip to content

Conversation

@pmhahn
Copy link

@pmhahn pmhahn commented Mar 24, 2025

Calling trace_pop_target() invalidates the linked list of target_stack_node_ts by free()ing the node and its p_target.

But p_stack_top may still points at that now freed node. Entering the debugger will crash as it will start from p_stack_top.

  1. Explicitly invalidate p_target by setting it to NULL.
  2. Explicitly pop the top node from p_stack_top before calling trace_pop_target().

Closes: #158

Calling `trace_pop_target()` invalidates the linked list of
`target_stack_node_t`s by `free()`ing the node and its `p_target`.

But `p_stack_top` may still points at that now freed node. Entering the
debugger will crash as it will start from `p_stack_top`.

1. Explicitly invalidate `p_target` by setting it to `NULL`.
2. Explicitly pop the top node from `p_stack_top` before calling
   `trace_pop_target()`.

Closes: Trepan-Debuggers#158
Signed-off-by: Philipp Hahn <[email protected]>
@rocky
Copy link
Collaborator

rocky commented Mar 24, 2025

Looks, good to me. Thanks!

@rocky rocky merged commit 67c74d6 into Trepan-Debuggers:remake-4-3 Mar 24, 2025
1 check passed
@pmhahn pmhahn deleted the sigsegv branch March 24, 2025 14:14
@pmhahn
Copy link
Author

pmhahn commented Mar 24, 2025

Looks, good to me. Thanks!

Actually it created the next bug: p_stack_top can be NULL and will now crash on p_stack_top->p_parent 😢

Core was generated by `/home/phahn/REPOS/LINUX/remake/make -C /home/phahn/GU/gu/KERNEL_brcma9_build/sr'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x00005f5d548d868a in update_file_1 (file=0x5f5d883c9240, depth=2, p_call_stack=0x5f5d883e3b30) at src/remake.c:880

warning: Source file is more recent than executable.
880	      p_stack_top = p_stack_top->p_parent;
(gdb) l
875	  if (file->command_state != cs_finished)
876	    {
877	      DBF (DB_VERBOSE, _("Recipe of '%s' is being run.\n"));
878	      if ( file->tracing & BRK_AFTER_CMD || i_debugger_stepping )
879		  enter_debugger(p_call_stack, file, 0, DEBUG_BRKPT_AFTER_CMD);
880	      p_stack_top = p_stack_top->p_parent;
881	      trace_pop_target(p_call_stack);
882	      return 0;
883	    }
884	
(gdb) p p_stack_top 
$1 = (target_stack_node_t *) 0x0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Entering debugger crashes

2 participants