Skip to content

Commit 0513a24

Browse files
committedFeb 23, 2019
Revert r354706 - lit touched my thigh
llvm-svn: 354711
1 parent 62619d0 commit 0513a24

12 files changed

+41
-99
lines changed
 

‎lldb/include/lldb/Target/Process.h

-2
Original file line numberDiff line numberDiff line change
@@ -2519,8 +2519,6 @@ class Process : public std::enable_shared_from_this<Process>,
25192519
///
25202520
//------------------------------------------------------------------
25212521
void RestoreProcessEvents();
2522-
2523-
bool IsHijackedForSynchronousResume();
25242522

25252523
const lldb::ABISP &GetABI();
25262524

‎lldb/include/lldb/Target/Target.h

+1-6
Original file line numberDiff line numberDiff line change
@@ -1153,19 +1153,14 @@ class Target : public std::enable_shared_from_this<Target>,
11531153

11541154
void SetIsActive(bool is_active) { m_active = is_active; }
11551155

1156-
void SetAutoContinue(bool auto_continue) {m_auto_continue = auto_continue;}
1157-
1158-
bool GetAutoContinue() const { return m_auto_continue; }
1159-
11601156
void GetDescription(Stream *s, lldb::DescriptionLevel level) const;
11611157

11621158
private:
11631159
lldb::TargetSP m_target_sp;
11641160
StringList m_commands;
11651161
lldb::SymbolContextSpecifierSP m_specifier_sp;
11661162
std::unique_ptr<ThreadSpec> m_thread_spec_up;
1167-
bool m_active = true;
1168-
bool m_auto_continue = false;
1163+
bool m_active;
11691164

11701165
// Use CreateStopHook to make a new empty stop hook. The GetCommandPointer
11711166
// and fill it with commands, and SetSpecifier to set the specifier shared
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
target stop-hook add -f stop-hook.c -l 29 -e 34 -o "expr ptr"
1+
target stop-hook add -f stop-hook.c -l 29 -e 34 -o "expr ptr"
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
target stop-hook add -f stop-hook.c -l 29 -e 34
22
expr ptr
3-
DONE
3+
DONE
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
break set -f stop-hook-threads.cpp -p "Break here to set up the stop hook"
21
break set -f stop-hook-threads.cpp -p "Break here to test that the stop-hook"
32
run
4-
target stop-hook add -G true
5-
expr lldb_val += 1
3+
target stop-hook add
4+
frame variable --show-globals g_val
65
thread list
6+
continue
77
DONE
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
break set -f stop-hook-threads.cpp -p "Break here to set up the stop hook"
21
break set -f stop-hook-threads.cpp -p "Break here to test that the stop-hook"
32
run
4-
target stop-hook add -x 2 -o "expr lldb_val += 1" -o "thread list"
5-
target stop-hook add -G true -o "script print('Hit stop hook')
3+
target stop-hook add -x 2 -o "frame variable thread_index"
4+
target stop-hook add -o continue

‎lldb/lit/ExecControl/StopHook/Inputs/stop-hook-threads.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ std::default_random_engine g_random_engine{std::random_device{}()};
1616
std::uniform_int_distribution<> g_distribution{0, 3000};
1717

1818
uint32_t g_val = 0;
19-
uint32_t lldb_val = 0;
2019

2120
uint32_t
2221
access_pool (bool flag = false)
@@ -63,8 +62,7 @@ thread_func (uint32_t thread_index)
6362
int main (int argc, char const *argv[])
6463
{
6564
std::thread threads[3];
66-
// Break here to set up the stop hook
67-
printf("Stop hooks engaged.\n");
65+
6866
// Create 3 threads
6967
for (auto &thread : threads)
7068
thread = std::thread{thread_func, std::distance(threads, &thread)};
@@ -73,7 +71,5 @@ int main (int argc, char const *argv[])
7371
for (auto &thread : threads)
7472
thread.join();
7573

76-
// print lldb_val so we can check it here.
77-
printf ("lldb_val was set to: %d.\n", lldb_val);
7874
return 0;
7975
}

‎lldb/lit/ExecControl/StopHook/stop-hook-threads.test

+10-8
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,31 @@
44
# RUN: %lldb -b -s %p/Inputs/stop-hook-threads-2.lldbinit -s %s -f %t \
55
# RUN: | FileCheck --check-prefix=CHECK --check-prefix=CHECK-FILTER %s
66
# XFAIL: system-windows
7+
# UNSUPPORTED: linux
78

89
thread list
910
break set -f stop-hook-threads.cpp -p "Set break point at this line"
1011
target stop-hook list
1112

1213
# CHECK: Hook: 1
1314
# CHECK-NEXT: State: enabled
14-
# CHECK-NO-FILTER-NEXT: AutoContinue on
1515
# CHECK-FILTER-NEXT: Thread
1616
# CHECK-FILTER-NEXT: index: 2
1717
# CHECK-NEXT: Commands:
18-
# CHECK-NEXT: expr lldb_val += 1
19-
# CHECK-NEXT: thread list
18+
# CHECK-NEXT: frame variable
2019

2120
# CHECK-FILTER: Hook: 2
2221
# CHECK-FILTER-NEXT: State: enabled
23-
# CHECK-FILTER-NEXT: AutoContinue on
2422
# CHECK-FILTER-NEXT: Commands:
25-
# CHECK-FILTER-NEXT: script print('Hit stop hook')
23+
# CHECK-FILTER-NEXT: continue
2624

2725
# Get the threads going
2826
continue
2927

30-
# Now make sure we hit the command the right number of times:
31-
# CHECK-NO-FILTER: lldb_val was set to: 15.
32-
# CHECK-FILTER: lldb_val was set to: 5.
28+
# When we filter per thread, we expect exactly 4 identical "frame var" results
29+
# CHECK-FILTER: (uint32_t) thread_index = [[THREAD_INDEX:[0-9]*]]
30+
# CHECK-FILTER-COUNT-3: (uint32_t) thread_index = [[THREAD_INDEX]]
31+
# CHECK-FILTER-NOT: thread_index
32+
33+
# When we don't filter, we expect to count 12 stopped threads in the thread list output
34+
# CHECK-NO-FILTER-COUNT-12: at stop-hook-threads.cpp{{.*}} stop reason = breakpoint

‎lldb/lit/ExecControl/StopHook/stop-hook.test

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
# string, so the test "passes" despite the fact that the commands failed
1212
# llvm.org/pr40119
1313
# UNSUPPORTED: system-windows
14-
# XFAIL: system-linux
1514

1615
break set -f stop-hook.c -p "// Set breakpoint here to test target stop-hook"
1716
break set -f stop-hook.c -p "// Another breakpoint which is outside of the stop-hook range"
@@ -47,7 +46,9 @@ target stop-hook list
4746
run
4847
# Stopping inside of the stop hook range
4948
# CHECK: (lldb) run
49+
# CHECK-NEXT: Process {{.*}} launched:
5050
# CHECK-NEXT: (void *) $0 = 0x
51+
# CHECK-NEXT: Process {{.*}} stopped
5152

5253
thread step-over
5354
# Stepping inside of the stop hook range

‎lldb/source/Commands/CommandObjectTarget.cpp

+6-23
Original file line numberDiff line numberDiff line change
@@ -4555,7 +4555,7 @@ class CommandObjectTargetSymbols : public CommandObjectMultiword {
45554555

45564556
static constexpr OptionDefinition g_target_stop_hook_add_options[] = {
45574557
// clang-format off
4558-
{ LLDB_OPT_SET_ALL, false, "one-liner", 'o', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeOneLiner, "Add a command for the stop hook. Can be specified more than once, and commands will be run in the order they appear." },
4558+
{ LLDB_OPT_SET_ALL, false, "one-liner", 'o', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeOneLiner, "Specify a one-line breakpoint command inline. Be sure to surround it with quotes." },
45594559
{ LLDB_OPT_SET_ALL, false, "shlib", 's', OptionParser::eRequiredArgument, nullptr, {}, CommandCompletions::eModuleCompletion, eArgTypeShlibName, "Set the module within which the stop-hook is to be run." },
45604560
{ LLDB_OPT_SET_ALL, false, "thread-index", 'x', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeThreadIndex, "The stop hook is run only for the thread whose index matches this argument." },
45614561
{ LLDB_OPT_SET_ALL, false, "thread-id", 't', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeThreadID, "The stop hook is run only for the thread whose TID matches this argument." },
@@ -4566,7 +4566,6 @@ static constexpr OptionDefinition g_target_stop_hook_add_options[] = {
45664566
{ LLDB_OPT_SET_1, false, "end-line", 'e', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeLineNum, "Set the end of the line range for which the stop-hook is to be run." },
45674567
{ LLDB_OPT_SET_2, false, "classname", 'c', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeClassName, "Specify the class within which the stop-hook is to be run." },
45684568
{ LLDB_OPT_SET_3, false, "name", 'n', OptionParser::eRequiredArgument, nullptr, {}, CommandCompletions::eSymbolCompletion, eArgTypeFunctionName, "Set the function name within which the stop hook will be run." },
4569-
{ LLDB_OPT_SET_ALL, false, "auto-continue",'G', OptionParser::eRequiredArgument, nullptr, {}, 0, eArgTypeBoolean, "The breakpoint will auto-continue after running its commands." },
45704569
// clang-format on
45714570
};
45724571

@@ -4607,17 +4606,6 @@ class CommandObjectTargetStopHookAdd : public CommandObjectParsed,
46074606
m_sym_ctx_specified = true;
46084607
break;
46094608

4610-
case 'G': {
4611-
bool value, success;
4612-
value = OptionArgParser::ToBoolean(option_arg, false, &success);
4613-
if (success) {
4614-
m_auto_continue = value;
4615-
} else
4616-
error.SetErrorStringWithFormat(
4617-
"invalid boolean value '%s' passed for -G option",
4618-
option_arg.str().c_str());
4619-
}
4620-
break;
46214609
case 'l':
46224610
if (option_arg.getAsInteger(0, m_line_start)) {
46234611
error.SetErrorStringWithFormat("invalid start line number: \"%s\"",
@@ -4673,7 +4661,7 @@ class CommandObjectTargetStopHookAdd : public CommandObjectParsed,
46734661

46744662
case 'o':
46754663
m_use_one_liner = true;
4676-
m_one_liner.push_back(option_arg);
4664+
m_one_liner = option_arg;
46774665
break;
46784666

46794667
default:
@@ -4702,7 +4690,6 @@ class CommandObjectTargetStopHookAdd : public CommandObjectParsed,
47024690

47034691
m_use_one_liner = false;
47044692
m_one_liner.clear();
4705-
m_auto_continue = false;
47064693
}
47074694

47084695
std::string m_class_name;
@@ -4721,8 +4708,7 @@ class CommandObjectTargetStopHookAdd : public CommandObjectParsed,
47214708
bool m_thread_specified;
47224709
// Instance variables to hold the values for one_liner options.
47234710
bool m_use_one_liner;
4724-
std::vector<std::string> m_one_liner;
4725-
bool m_auto_continue;
4711+
std::string m_one_liner;
47264712
};
47274713

47284714
CommandObjectTargetStopHookAdd(CommandInterpreter &interpreter)
@@ -4847,13 +4833,10 @@ class CommandObjectTargetStopHookAdd : public CommandObjectParsed,
48474833

48484834
new_hook_sp->SetThreadSpecifier(thread_spec);
48494835
}
4850-
4851-
new_hook_sp->SetAutoContinue(m_options.m_auto_continue);
48524836
if (m_options.m_use_one_liner) {
4853-
// Use one-liners.
4854-
for (auto cmd : m_options.m_one_liner)
4855-
new_hook_sp->GetCommandPointer()->AppendString(
4856-
cmd.c_str());
4837+
// Use one-liner.
4838+
new_hook_sp->GetCommandPointer()->AppendString(
4839+
m_options.m_one_liner.c_str());
48574840
result.AppendMessageWithFormat("Stop hook #%" PRIu64 " added.\n",
48584841
new_hook_sp->GetID());
48594842
} else {

‎lldb/source/Target/Process.cpp

+6-22
Original file line numberDiff line numberDiff line change
@@ -1615,8 +1615,6 @@ Status Process::Resume() {
16151615
return error;
16161616
}
16171617

1618-
static const char *g_resume_sync_name = "lldb.Process.ResumeSynchronous.hijack";
1619-
16201618
Status Process::ResumeSynchronous(Stream *stream) {
16211619
Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_STATE |
16221620
LIBLLDB_LOG_PROCESS));
@@ -1630,7 +1628,7 @@ Status Process::ResumeSynchronous(Stream *stream) {
16301628
}
16311629

16321630
ListenerSP listener_sp(
1633-
Listener::MakeListener(g_resume_sync_name));
1631+
Listener::MakeListener("lldb.Process.ResumeSynchronous.hijack"));
16341632
HijackProcessEvents(listener_sp);
16351633

16361634
Status error = PrivateResume();
@@ -1654,11 +1652,6 @@ Status Process::ResumeSynchronous(Stream *stream) {
16541652
return error;
16551653
}
16561654

1657-
bool Process::IsHijackedForSynchronousResume() {
1658-
const char *hijacker_name = GetHijackingListenerName();
1659-
return strcmp(hijacker_name, g_resume_sync_name) == 0;
1660-
}
1661-
16621655
StateType Process::GetPrivateState() { return m_private_state.GetValue(); }
16631656

16641657
void Process::SetPrivateState(StateType new_state) {
@@ -4267,20 +4260,11 @@ void Process::ProcessEventData::DoOnRemoval(Event *event_ptr) {
42674260
// public resume.
42684261
process_sp->PrivateResume();
42694262
} else {
4270-
bool hijacked =
4271-
process_sp->IsHijackedForEvent(eBroadcastBitStateChanged)
4272-
&& !process_sp->IsHijackedForSynchronousResume();
4273-
4274-
if (!hijacked) {
4275-
// If we didn't restart, run the Stop Hooks here.
4276-
// Don't do that if state changed events aren't hooked up to the
4277-
// public (or SyncResume) broadcasters. StopHooks are just for
4278-
// real public stops. They might also restart the target,
4279-
// so watch for that.
4280-
process_sp->GetTarget().RunStopHooks();
4281-
if (process_sp->GetPrivateState() == eStateRunning)
4282-
SetRestarted(true);
4283-
}
4263+
// If we didn't restart, run the Stop Hooks here: They might also
4264+
// restart the target, so watch for that.
4265+
process_sp->GetTarget().RunStopHooks();
4266+
if (process_sp->GetPrivateState() == eStateRunning)
4267+
SetRestarted(true);
42844268
}
42854269
}
42864270
}

‎lldb/source/Target/Target.cpp

+8-24
Original file line numberDiff line numberDiff line change
@@ -2554,14 +2554,12 @@ void Target::RunStopHooks() {
25542554

25552555
StopHookCollection::iterator pos, end = m_stop_hooks.end();
25562556

2557-
// If there aren't any active stop hooks, don't bother either.
2558-
// Also see if any of the active hooks want to auto-continue.
2557+
// If there aren't any active stop hooks, don't bother either:
25592558
bool any_active_hooks = false;
2560-
bool auto_continue = false;
2561-
for (auto hook : m_stop_hooks) {
2562-
if (hook.second->IsActive()) {
2559+
for (pos = m_stop_hooks.begin(); pos != end; pos++) {
2560+
if ((*pos).second->IsActive()) {
25632561
any_active_hooks = true;
2564-
auto_continue |= hook.second->GetAutoContinue();
2562+
break;
25652563
}
25662564
}
25672565
if (!any_active_hooks)
@@ -2597,7 +2595,6 @@ void Target::RunStopHooks() {
25972595
bool hooks_ran = false;
25982596
bool print_hook_header = (m_stop_hooks.size() != 1);
25992597
bool print_thread_header = (num_exe_ctx != 1);
2600-
bool did_restart = false;
26012598

26022599
for (pos = m_stop_hooks.begin(); keep_going && pos != end; pos++) {
26032600
// result.Clear();
@@ -2642,13 +2639,10 @@ void Target::RunStopHooks() {
26422639
options.SetPrintResults(true);
26432640
options.SetAddToHistory(false);
26442641

2645-
// Force Async:
2646-
bool old_async = GetDebugger().GetAsyncExecution();
2647-
GetDebugger().SetAsyncExecution(true);
26482642
GetDebugger().GetCommandInterpreter().HandleCommands(
26492643
cur_hook_sp->GetCommands(), &exc_ctx_with_reasons[i], options,
26502644
result);
2651-
GetDebugger().SetAsyncExecution(old_async);
2645+
26522646
// If the command started the target going again, we should bag out of
26532647
// running the stop hooks.
26542648
if ((result.GetStatus() == eReturnStatusSuccessContinuingNoResult) ||
@@ -2657,19 +2651,13 @@ void Target::RunStopHooks() {
26572651
StopHookCollection::iterator tmp = pos;
26582652
if (++tmp != end)
26592653
result.AppendMessageWithFormat("\nAborting stop hooks, hook %" PRIu64
2660-
" set the program running.\n"
2661-
" Consider using '-G true' to make "
2662-
"stop hooks auto-continue.\n",
2654+
" set the program running.\n",
26632655
cur_hook_sp->GetID());
26642656
keep_going = false;
2665-
did_restart = true;
26662657
}
26672658
}
26682659
}
26692660
}
2670-
// Finally, if auto-continue was requested, do it now:
2671-
if (!did_restart && auto_continue)
2672-
m_process_sp->PrivateResume();
26732661

26742662
result.GetImmediateOutputStream()->Flush();
26752663
result.GetImmediateErrorStream()->Flush();
@@ -3155,13 +3143,12 @@ void Target::FinalizeFileActions(ProcessLaunchInfo &info) {
31553143
//--------------------------------------------------------------
31563144
Target::StopHook::StopHook(lldb::TargetSP target_sp, lldb::user_id_t uid)
31573145
: UserID(uid), m_target_sp(target_sp), m_commands(), m_specifier_sp(),
3158-
m_thread_spec_up() {}
3146+
m_thread_spec_up(), m_active(true) {}
31593147

31603148
Target::StopHook::StopHook(const StopHook &rhs)
31613149
: UserID(rhs.GetID()), m_target_sp(rhs.m_target_sp),
31623150
m_commands(rhs.m_commands), m_specifier_sp(rhs.m_specifier_sp),
3163-
m_thread_spec_up(), m_active(rhs.m_active),
3164-
m_auto_continue(rhs.m_auto_continue) {
3151+
m_thread_spec_up(), m_active(rhs.m_active) {
31653152
if (rhs.m_thread_spec_up)
31663153
m_thread_spec_up.reset(new ThreadSpec(*rhs.m_thread_spec_up));
31673154
}
@@ -3188,9 +3175,6 @@ void Target::StopHook::GetDescription(Stream *s,
31883175
else
31893176
s->Indent("State: disabled\n");
31903177

3191-
if (m_auto_continue)
3192-
s->Indent("AutoContinue on\n");
3193-
31943178
if (m_specifier_sp) {
31953179
s->Indent();
31963180
s->PutCString("Specifier:\n");

0 commit comments

Comments
 (0)
Please sign in to comment.