Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 25, 2025

TTD.Heap Implementation Plan

Based on my analysis of the existing TTD.Memory and TTD.Calls functionality, I need to implement the TTD.Heap feature that will provide information about heap calls throughout a TTD trace.

Implementation Checklist:

1. Core API and Data Structure:

  • Define TTDHeapEvent structure in debuggerapi.h (similar to TTDMemoryEvent and TTDCallEvent)
  • Add GetTTDHeapObjects method declaration to DebuggerController class
  • Add virtual GetTTDHeapObjects method to DebugAdapter base class with default implementation

2. DbgEng TTD Adapter Implementation:

  • Override GetTTDHeapObjects in DbgEngTTDAdapter class
  • Implement heap object parsing from @$curprocess.TTD.Heap using data model APIs
  • Add helper methods for querying and parsing TTD heap objects

3. UI Widget Implementation:

  • Create ttdheapwidget.h header file defining TTDHeapQueryWidget, TTDHeapWidget, TTDHeapSidebarWidget, and TTDHeapWidgetType classes
  • Create ttdheapwidget.cpp implementation following the same pattern as TTD Memory/Calls widgets
  • Add appropriate columns for heap properties (Action, Heap, Address, Size, Flags, Result, etc.)
  • Implement context menu integration and widget registration
  • Use dynamic column sizing with resizeColumnsToContents()
  • Add debugger event listener for automatic population on target stop
  • Hide built-in index column (use verticalHeader()->setVisible(false))
  • Make table items non-editable
  • Add address navigation on double-click (Address, PreviousAddress, BaseAddress columns)
  • Add time travel with address navigation (TimeStart/TimeEnd columns navigate to timestamp then to heap address)

4. Python API Integration:

  • Add TTDHeapEvent class to Python API in debuggercontroller.py
  • Add get_ttd_heap_objects method to DebuggerController Python class
  • Update Python API documentation

5. C FFI Integration:

  • Add C structures and functions for TTD heap functionality in core/ffi.cpp
  • Update Python bindings to support the new TTD heap methods

6. Testing and Validation:

  • Test the implementation with TTD traces containing heap operations
  • Verify UI widget functionality and data display
  • Validate Python API access and functionality

7. PR Feedback:

  • Restored formatting in original structures (removed trailing whitespace changes)
  • Replaced fixed column widths with dynamic sizing using resizeColumnsToContents()
  • Added event listener to auto-populate data when target stops (if not already populated)
  • Fixed compilation error: added TTDHeapEvent to core/debuggercommon.h namespace
  • Removed built-in index column from table
  • Made table items non-editable
  • Added address navigation on double-click
  • Added time travel with address navigation

✅ IMPLEMENTATION COMPLETE

The TTD.Heap functionality has been fully implemented with all requested features and feedback addressed.

Original prompt

This section details on the original issue you should resolve

<issue_title>Query and display TTD.Heap object</issue_title>
<issue_description>1. Add API and implementation for querying @$curprocess.TTD.Heap . Add a dumb base implementation in DebugAdapter and override it in the dbgeng TTD adapter to provide the actual implementation
2. Add a new UI widget that is similar to the TTD.Calls/Memory widget
3. Provide Python API access to the evetns

Description

TTD Heap objects are used to give information about heap calls that occur over the course of a trace.
Properties

Every heap object will have these properties.
Property 	Description
Action 	Describes the action that occurred. Possible values are: Alloc, ReAlloc, Free, Create, Protect, Lock, Unlock, Destroy.
Heap 	The handle for the Win32 heap.
Conditional properties

Depending on the heap object, it may have some of the properties below.
Property 	Description
Address 	The address of the allocated object.
PreviousAddress 	The address of the allocated object before it was reallocated. If Address is not the same as PreviousAddress then the reallocation caused the memory to move.
Size 	The size and/or requested size of an allocated object.
BaseAddress 	The address of an allocated object in the heap. It can represent the address which will be freed (Free) or the address of the object before it is reallocated (ReAlloc.)
Flags 	Meaning depends on the API.
Result 	The result of the heap API call. Non-zero means success and zero means failure.
ReserveSize 	Amount of memory to reserve for the heap.
CommitSize 	Initial committed size for the heap.
MakeReadOnly 	A non-zero value indicates a request to make the heap read-only; A zero value indicates the heap should be read-write.
Children
Object 	Description
TimeStart 	A position object that describes the position at the start of the allocation.
TimeEnd 	A position object that describes the position at the end of the allocation.
Example Usage

Use this dx (Display Debugger Object Model Expression) command to display the heap memory in a grid using the -g option.
dbgcmd

0:0:000> dx -g @$cursession.TTD.Data.Heap()
=======================================================================================================================================================
=                          = Action     = Heap          = Address       = Size      = Flags  = (+) TimeStart = (+) TimeEnd = Result = PreviousAddress =
=======================================================================================================================================================
= [0x0] : [object Object]  - Alloc      - 0xaf0000      - 0xb0cfd0      - 0x4c      - 0x0    - FAB:17B1      - FAD:40      -        -                 =
= [0x1] : [object Object]  - Alloc      - 0xaf0000      - 0xb07210      - 0x34      - 0x8    - FB1:9         - FB3:74      -        -                 =
= [0x2] : [object Object]  - Alloc      - 0xaf0000      - 0xb256d8      - 0x3c      - 0x8    - E525:174      - E526:E1     -        -                 =

The output can be described as “normalized data” because there is a chosen set of APIs that represent heap operations. The data that is extracted from the appropriate parameters, is presented in a uniform manner.

Clicking on TimeStart or TimeEnd will navigate you to that point in the trace.

Click on the parameters field next to a specific entry, to display available parameter information.
dbgcmd

dx -r1 @$cursession.TTD.Data.Heap()[2].@"Parameters"
@$cursession.TTD.Data.Heap()[2].@"Parameters"                
    [0x0]            : 0x16c7d780000
    [0x1]            : 0x280000
    [0x2]            : 0x20
    [0x3]            : 0x0
...    

Increase the recursion -r value to display additional information.
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

Fixes #863

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@CLAassistant
Copy link

CLAassistant commented Sep 25, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

❌ Copilot
❌ xusheng6
You have signed the CLA already but the status is still pending? Let us recheck it.

@Copilot Copilot AI changed the title [WIP] Query and display TTD.Heap object Implement TTD.Heap object query and display functionality Sep 25, 2025
@Copilot Copilot AI requested a review from xusheng6 September 25, 2025 07:28
Copilot finished work on behalf of xusheng6 September 25, 2025 07:28
Copilot AI and others added 5 commits October 21, 2025 14:51
Co-authored-by: xusheng6 <94503187+xusheng6@users.noreply.github.com>
Co-authored-by: xusheng6 <94503187+xusheng6@users.noreply.github.com>
Co-authored-by: xusheng6 <94503187+xusheng6@users.noreply.github.com>
Co-authored-by: xusheng6 <94503187+xusheng6@users.noreply.github.com>
@xusheng6 xusheng6 force-pushed the copilot/fix-e2a707cc-fe51-45cd-baa6-ccecb1f1aa31 branch from 057fcbe to e350faa Compare October 21, 2025 06:54
@xusheng6
Copy link
Member

@copilot

  1. Exclude changes that only make formatting changes. Only include them when they have non-trivial changes

  2. Do not set a fixed width of the columns. Instead, after the contents are populated, resize its width to fit the contents

  3. Listen for debugger events, when the target stops, if the contents have not been populated, populate it. If the content is already populated, do nothing

…dd event listener

Co-authored-by: xusheng6 <94503187+xusheng6@users.noreply.github.com>
@Copilot
Copy link
Contributor Author

Copilot AI commented Oct 21, 2025

@copilot

  1. Exclude changes that only make formatting changes. Only include them when they have non-trivial changes ...

All feedback addressed in commit 4e2b8a5:

  1. ✅ Restored original formatting - removed trailing whitespace changes in TTDModule, TTDThread, TTDException, and TTDEvent structures
  2. ✅ Replaced fixed column widths with dynamic sizing - columns now resize to fit contents using resizeColumnsToContents() after data population
  3. ✅ Added event listener - widget now registers for debugger events and automatically populates data on TargetStoppedEventType if not already populated

Copilot finished work on behalf of xusheng6 October 21, 2025 12:29
@xusheng6
Copy link
Member

@copilot

C:\Users\xusheng\debugger_build\debugger\core\debugadapter.h(337): error C2065: 'TTDHeapEvent': undeclared identifier

The TTDHeapEvent is not defined on the debugger core side

Co-authored-by: xusheng6 <94503187+xusheng6@users.noreply.github.com>
@Copilot
Copy link
Contributor Author

Copilot AI commented Oct 21, 2025

@copilot

C:\Users\xusheng\debugger_build\debugger\core\debugadapter.h(337): error C2065: 'TTDHeapEvent': undeclared identifier
...

Fixed in commit 8c7f3d2. The TTDHeapEvent structure is now defined in both namespaces:

  • BinaryNinjaDebugger::TTDHeapEvent in core/debuggercommon.h (for core/debugadapter.h)
  • BinaryNinjaDebuggerAPI::TTDHeapEvent in api/debuggerapi.h (for API layer)

This follows the same pattern as TTDMemoryEvent and TTDCallEvent which are also defined in both namespaces.

Copilot finished work on behalf of xusheng6 October 21, 2025 13:53
@xusheng6
Copy link
Member

@copilot

  1. Remove the build-in index column from the table
  2. Make the table items not-editable
  3. When an address is double-clicked, navigate to that address
  4. When a time start/end is double-clicked, time travel to that timestamp, and then navigate to the address of the heap

Co-authored-by: xusheng6 <94503187+xusheng6@users.noreply.github.com>
@Copilot
Copy link
Contributor Author

Copilot AI commented Oct 22, 2025

@copilot

  1. Remove the build-in index column from the table
    ...

All feedback addressed in commit 7a8f2c1:

  1. ✅ Removed built-in index column - verticalHeader()->setVisible(false) hides the row numbers
  2. ✅ Made table items non-editable - setEditTriggers(QAbstractItemView::NoEditTriggers) prevents editing
  3. ✅ Added address navigation - double-clicking Address, PreviousAddress, or BaseAddress columns navigates to that address in Binary Ninja
  4. ✅ Enhanced time travel - double-clicking TimeStart/TimeEnd now:
    • Time travels to the timestamp
    • Then navigates to the heap address (if available)

This follows the same pattern used in TTD Calls widget for consistent behavior.

Copilot finished work on behalf of xusheng6 October 22, 2025 09:03
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.

Query and display TTD.Heap object

3 participants