Skip to content

Commit

Permalink
[trace][intelpt] fix some test failures
Browse files Browse the repository at this point in the history
Minor fixes needed and now `./bin/lldb-dotest -p TestTrace` passes
correctly.

- There was an incorrect iteration.
- Some error messages changed.
- The way repeat commands are handled changed a bit, so I had to create
a new --continue arg in "thread trace dump instructions" to handle this
correctly.

Differential Revision: https://reviews.llvm.org/D122023
  • Loading branch information
walter-erquinigo committed Mar 18, 2022
1 parent 217f267 commit b7d525a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
31 changes: 14 additions & 17 deletions lldb/source/Commands/CommandObjectThread.cpp
Expand Up @@ -2032,7 +2032,7 @@ class CommandObjectTraceExport : public CommandObjectMultiword {

unsigned i = 0;
for (llvm::StringRef plugin_name =
PluginManager::GetTraceExporterPluginNameAtIndex(i++);
PluginManager::GetTraceExporterPluginNameAtIndex(i);
!plugin_name.empty();
plugin_name = PluginManager::GetTraceExporterPluginNameAtIndex(i++)) {
if (ThreadTraceExportCommandCreator command_creator =
Expand Down Expand Up @@ -2147,6 +2147,10 @@ class CommandObjectTraceDumpInstructions
m_show_tsc = true;
break;
}
case 'C': {
m_continue = true;
break;
}
default:
llvm_unreachable("Unimplemented option");
}
Expand All @@ -2159,6 +2163,7 @@ class CommandObjectTraceDumpInstructions
m_raw = false;
m_forwards = false;
m_show_tsc = false;
m_continue = false;
}

llvm::ArrayRef<OptionDefinition> GetDefinitions() override {
Expand All @@ -2173,6 +2178,7 @@ class CommandObjectTraceDumpInstructions
bool m_raw;
bool m_forwards;
bool m_show_tsc;
bool m_continue;
};

CommandObjectTraceDumpInstructions(CommandInterpreter &interpreter)
Expand All @@ -2192,24 +2198,19 @@ class CommandObjectTraceDumpInstructions

llvm::Optional<std::string> GetRepeatCommand(Args &current_command_args,
uint32_t index) override {
current_command_args.GetCommandString(m_repeat_command);
m_create_repeat_command_just_invoked = true;
return m_repeat_command;
std::string cmd;
current_command_args.GetCommandString(cmd);
if (cmd.find("--continue") == std::string::npos)
cmd += " --continue";
return cmd;
}

protected:
bool DoExecute(Args &args, CommandReturnObject &result) override {
if (!IsRepeatCommand())
if (!m_options.m_continue)
m_dumpers.clear();

bool status = CommandObjectIterateOverThreads::DoExecute(args, result);

m_create_repeat_command_just_invoked = false;
return status;
}

bool IsRepeatCommand() {
return !m_repeat_command.empty() && !m_create_repeat_command_just_invoked;
return CommandObjectIterateOverThreads::DoExecute(args, result);
}

bool HandleOneThread(lldb::tid_t tid, CommandReturnObject &result) override {
Expand Down Expand Up @@ -2249,10 +2250,6 @@ class CommandObjectTraceDumpInstructions
}

CommandOptions m_options;

// Repeat command helpers
std::string m_repeat_command;
bool m_create_repeat_command_just_invoked = false;
std::map<lldb::tid_t, std::unique_ptr<TraceInstructionDumper>> m_dumpers;
};

Expand Down
6 changes: 6 additions & 0 deletions lldb/source/Commands/Options.td
Expand Up @@ -1116,6 +1116,12 @@ let Command = "thread trace dump instructions" in {
def thread_trace_dump_instructions_show_tsc : Option<"tsc", "t">,
Group<1>,
Desc<"For each instruction, print the corresponding timestamp counter if available.">;
def thread_trace_dump_instructions_continue: Option<"continue", "C">,
Group<1>,
Desc<"Continue dumping instructions right where the previous invocation of this "
"command was left, or from the beginning if this is the first invocation. The --skip "
"argument is discarded and the other arguments are preserved from the previous "
"invocation when possible.">;
}

let Command = "thread trace dump info" in {
Expand Down
2 changes: 1 addition & 1 deletion lldb/test/API/commands/trace/TestTraceDumpInfo.py
Expand Up @@ -18,7 +18,7 @@ def testErrorMessages(self):
os.path.join(self.getSourceDir(), "intelpt-trace", "a.out"))

self.expect("thread trace dump info",
substrs=["error: invalid process"],
substrs=["error: Command requires a current process."],
error=True)

# Now we check the output when there's a running target without a trace
Expand Down
2 changes: 1 addition & 1 deletion lldb/test/API/commands/trace/TestTraceDumpInstructions.py
Expand Up @@ -19,7 +19,7 @@ def testErrorMessages(self):
os.path.join(self.getSourceDir(), "intelpt-trace", "a.out"))

self.expect("thread trace dump instructions",
substrs=["error: invalid process"],
substrs=["error: Command requires a current process."],
error=True)

# Now we check the output when there's a running target without a trace
Expand Down
3 changes: 1 addition & 2 deletions lldb/test/API/commands/trace/TestTraceExport.py
Expand Up @@ -23,7 +23,7 @@ def testErrorMessages(self):
os.path.join(self.getSourceDir(), "intelpt-trace", "a.out"))

self.expect(f"thread trace export ctf --file {ctf_test_file}",
substrs=["error: invalid process"],
substrs=["error: Command requires a current process."],
error=True)

# Now we check the output when there's a running target without a trace
Expand Down Expand Up @@ -172,4 +172,3 @@ def testHtrBasicSuperBlockPassSequenceCheck(self):
data_index = index_of_first_layer_1_block
for i in range(len(expected_block_names)):
self.assertTrue(data[data_index + i]['name'] == expected_block_names[i])

2 changes: 1 addition & 1 deletion lldb/test/API/commands/trace/TestTraceSave.py
Expand Up @@ -18,7 +18,7 @@ def testErrorMessages(self):
os.path.join(self.getSourceDir(), "intelpt-trace", "a.out"))

self.expect("process trace save",
substrs=["error: invalid process"],
substrs=["error: Command requires a current process."],
error=True)

# Now we check the output when there's a running target without a trace
Expand Down

0 comments on commit b7d525a

Please sign in to comment.