@@ -379,75 +379,85 @@ TTDPosition DbgEngTTDAdapter::GetCurrentTTDPosition()
379379 return position;
380380 }
381381
382- // Use data model API to get current TTD position
383- std::string output = EvaluateDataModelExpression ( " @$cursession.TTD.Position " );
382+ // Always use the !position command to retrieve the current timestamp
383+ std::string output = InvokeBackendCommand ( " !position " );
384384
385- if (!output.empty () && output != " complex_result " )
385+ if (!output.empty ())
386386 {
387- // Parse the position output (format like "1A0:12F ")
388- size_t colonPos = output.find (' : ' );
389- if (colonPos != std::string::npos)
387+ // Parse the position output (format like "Time Travel Position: 602C:0 ")
388+ size_t prefixPos = output.find (" Time Travel Position: " );
389+ if (prefixPos != std::string::npos)
390390 {
391- try
391+ // Find the position data after the prefix
392+ size_t dataStart = prefixPos + strlen (" Time Travel Position:" );
393+ std::string positionData = output.substr (dataStart);
394+
395+ // Find the colon in the position data
396+ size_t colonPos = positionData.find (' :' );
397+ if (colonPos != std::string::npos)
392398 {
393- std::string seqStr = output.substr (0 , colonPos);
394- std::string stepStr = output.substr (colonPos + 1 );
395-
396- // Remove any non-hex characters
397- seqStr.erase (std::remove_if (seqStr.begin (), seqStr.end (),
398- [](char c) { return !std::isxdigit (c); }), seqStr.end ());
399- stepStr.erase (std::remove_if (stepStr.begin (), stepStr.end (),
400- [](char c) { return !std::isxdigit (c); }), stepStr.end ());
401-
402- if (!seqStr.empty () && !stepStr.empty ())
399+ try
403400 {
404- position.sequence = std::stoull (seqStr, nullptr , 16 );
405- position.step = std::stoull (stepStr, nullptr , 16 );
401+ std::string seqStr = positionData.substr (0 , colonPos);
402+ std::string stepStr = positionData.substr (colonPos + 1 );
403+
404+ // Remove any non-hex characters
405+ seqStr.erase (std::remove_if (seqStr.begin (), seqStr.end (),
406+ [](char c) { return !std::isxdigit (c); }), seqStr.end ());
407+ stepStr.erase (std::remove_if (stepStr.begin (), stepStr.end (),
408+ [](char c) { return !std::isxdigit (c); }), stepStr.end ());
409+
410+ if (!seqStr.empty () && !stepStr.empty ())
411+ {
412+ position.sequence = std::stoull (seqStr, nullptr , 16 );
413+ position.step = std::stoull (stepStr, nullptr , 16 );
414+ }
415+ }
416+ catch (const std::exception& e)
417+ {
418+ LogError (" Failed to parse TTD position: %s" , e.what ());
406419 }
407- }
408- catch (const std::exception& e)
409- {
410- LogError (" Failed to parse TTD position: %s" , e.what ());
411420 }
412421 }
413- }
414- else
415- {
416- // Fallback to command interface if data model doesn't work
417- LogWarn (" Data model evaluation failed, falling back to command interface" );
418- std::string output = InvokeBackendCommand (" !position" );
419-
420- // Parse the position output (format like "1A0:12F")
421- size_t colonPos = output.find (' :' );
422- if (colonPos != std::string::npos)
422+ else
423423 {
424- try
424+ // Fallback: try to find a simple "XXXX:Y" pattern in the output
425+ size_t colonPos = output.find (' :' );
426+ if (colonPos != std::string::npos)
425427 {
426- std::string seqStr = output.substr (0 , colonPos);
427- std::string stepStr = output.substr (colonPos + 1 );
428-
429- // Remove any non-hex characters
430- seqStr.erase (std::remove_if (seqStr.begin (), seqStr.end (),
431- [](char c) { return !std::isxdigit (c); }), seqStr.end ());
432- stepStr.erase (std::remove_if (stepStr.begin (), stepStr.end (),
433- [](char c) { return !std::isxdigit (c); }), stepStr.end ());
434-
435- if (!seqStr.empty () && !stepStr.empty ())
428+ try
436429 {
437- position.sequence = std::stoull (seqStr, nullptr , 16 );
438- position.step = std::stoull (stepStr, nullptr , 16 );
430+ // Look backwards from colon to find start of hex sequence
431+ size_t seqStart = colonPos;
432+ while (seqStart > 0 && std::isxdigit (output[seqStart - 1 ]))
433+ seqStart--;
434+
435+ // Look forwards from colon to find end of hex step
436+ size_t stepEnd = colonPos + 1 ;
437+ while (stepEnd < output.length () && std::isxdigit (output[stepEnd]))
438+ stepEnd++;
439+
440+ if (seqStart < colonPos && stepEnd > colonPos + 1 )
441+ {
442+ std::string seqStr = output.substr (seqStart, colonPos - seqStart);
443+ std::string stepStr = output.substr (colonPos + 1 , stepEnd - colonPos - 1 );
444+
445+ if (!seqStr.empty () && !stepStr.empty ())
446+ {
447+ position.sequence = std::stoull (seqStr, nullptr , 16 );
448+ position.step = std::stoull (stepStr, nullptr , 16 );
449+ }
450+ }
451+ }
452+ catch (const std::exception& e)
453+ {
454+ LogError (" Failed to parse TTD position from fallback parsing: %s" , e.what ());
439455 }
440- }
441- catch (const std::exception& e)
442- {
443- LogError (" Failed to parse TTD position: %s" , e.what ());
444456 }
445457 }
446458 }
447459
448460 return position;
449-
450- return position;
451461}
452462
453463bool DbgEngTTDAdapter::SetTTDPosition (const TTDPosition& position)
0 commit comments