Skip to content

Commit 8647cd8

Browse files
Copilotxusheng6
andcommitted
Add max query results setting for TTD Memory and TTD Calls queries
Co-authored-by: xusheng6 <[email protected]>
1 parent f1506be commit 8647cd8

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

core/adapters/dbgengttdadapter.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,16 @@ Ref<Settings> DbgEngTTDAdapterType::RegisterAdapterSettings()
352352
"readOnly" : false,
353353
"uiSelectionAction" : "file"
354354
})");
355+
settings->RegisterSetting("ttd.maxQueryResults",
356+
R"({
357+
"title" : "Max Query Results",
358+
"type" : "number",
359+
"default" : 10000,
360+
"minValue" : 1,
361+
"maxValue" : 1000000,
362+
"description" : "Maximum number of results to return from TTD Memory and TTD Calls queries to prevent performance issues with large traces",
363+
"readOnly" : false
364+
})");
355365

356366
return settings;
357367
}
@@ -497,8 +507,13 @@ bool DbgEngTTDAdapter::QueryMemoryAccessByAddress(uint64_t startAddress, uint64_
497507
return false;
498508
}
499509

500-
// Create the actual TTD memory query expression
501-
std::string expression = fmt::format("@$cursession.TTD.Memory(0x{:x},0x{:x},\"{}\")", startAddress, endAddress, accessTypeStr);
510+
// Get the max results setting
511+
auto adapterSettings = GetAdapterSettings();
512+
BNSettingsScope scope = SettingsResourceScope;
513+
auto maxResults = adapterSettings->Get<uint64_t>("ttd.maxQueryResults", GetData(), &scope);
514+
515+
// Create the actual TTD memory query expression with result limit
516+
std::string expression = fmt::format("@$cursession.TTD.Memory(0x{:x},0x{:x},\"{}\").Take({})", startAddress, endAddress, accessTypeStr, maxResults);
502517

503518
LogInfo("Executing TTD memory query: %s", expression.c_str());
504519

@@ -509,7 +524,7 @@ bool DbgEngTTDAdapter::QueryMemoryAccessByAddress(uint64_t startAddress, uint64_
509524
return false;
510525
}
511526

512-
LogInfo("Successfully retrieved %zu TTD memory events", events.size());
527+
LogInfo("Successfully retrieved %zu TTD memory events (limited to %llu)", events.size(), maxResults);
513528
return true;
514529
}
515530
catch (const std::exception& e)
@@ -982,6 +997,13 @@ bool DbgEngTTDAdapter::QueryCallsForSymbols(const std::vector<std::string>& symb
982997
fmt::format("{:x}", endReturnAddress) + ")";
983998
}
984999

1000+
// Get the max results setting and add Take() to limit results
1001+
auto adapterSettings = GetAdapterSettings();
1002+
BNSettingsScope scope = SettingsResourceScope;
1003+
auto maxResults = adapterSettings->Get<uint64_t>("ttd.maxQueryResults", GetData(), &scope);
1004+
1005+
expression += fmt::format(".Take({})", maxResults);
1006+
9851007
LogInfo("Executing TTD calls query: %s", expression.c_str());
9861008

9871009
return ParseTTDCallObjects(expression, events);

ui/ttdmemorywidget.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,20 @@ void TTDMemoryQueryWidget::performQuery()
418418
}
419419

420420
updateStatus(QString("Found %1 memory access events").arg(events.size()));
421+
422+
// Check if results might be truncated by comparing with max results setting
423+
if (m_controller && m_controller->GetAdapterSettings())
424+
{
425+
auto adapterSettings = m_controller->GetAdapterSettings();
426+
BNSettingsScope scope = SettingsResourceScope;
427+
auto maxResults = adapterSettings->Get<uint64_t>("ttd.maxQueryResults", m_data, &scope);
428+
429+
if (events.size() >= maxResults)
430+
{
431+
updateStatus(QString("Found %1 memory access events (results may be truncated at limit of %2)")
432+
.arg(events.size()).arg(maxResults));
433+
}
434+
}
421435
}
422436
catch (const std::exception& e)
423437
{

0 commit comments

Comments
 (0)