Second part of indicating when the user is stopped in optimized code.
The first part was in r243508 -- the extent of the UI changes in that
patchset was to add "[opt]" to the frame-format when a stack frame was
built with optimized code.
In this change, when a stack frame built with optimization is selected,
a message will be printed to the async output channel --
opt1.c was compiled with optimization - stepping may behave oddly; variables may not be available.
The warning will be only be printed once per source file in a debug session.
These warnings may be disabled by
settings set target.process.optimization-warnings false
Internally, a new Process::PrintWarning() method has been added for
warnings that we want to print only once to the user. It takes a type
of warning (currently only eWarningsOptimization) and an object
pointer (CompileUnit*) - the warning will only be printed once for a
given object pointer value.
This is a bit of a prototype of this change - I think we will be
tweaking it more in the future. But I wanted to land this and see
how it goes. Advanced users will find these warnings unnecessary
noise and will quickly disable them - but anyone who maintains a
debugger knows that debugging optimized code, without realizing it,
is a constant source of confusion and frustation for more typical
debugger users.
I imagine there will be more of these "warn once per whatever" style
warnings that we will want to add in the future and we'll need to
come up with a better way for enabling/disabling them. But I'm not
srue what form that warning settings should take and I didn't want
to code up something that we regret later, so for now I just added
another process setting for this one warning.
<rdar://problem/19281172>
llvm-svn: 244190
diff --git a/lldb/source/Target/Process.cpp b/lldb/source/Target/Process.cpp
index 9594a8a..adc393f 100644
--- a/lldb/source/Target/Process.cpp
+++ b/lldb/source/Target/Process.cpp
@@ -115,6 +115,7 @@
{ "stop-on-sharedlibrary-events" , OptionValue::eTypeBoolean, true, false, NULL, NULL, "If true, stop when a shared library is loaded or unloaded." },
{ "detach-keeps-stopped" , OptionValue::eTypeBoolean, true, false, NULL, NULL, "If true, detach will attempt to keep the process stopped." },
{ "memory-cache-line-size" , OptionValue::eTypeUInt64, false, 512, NULL, NULL, "The memory cache line size" },
+ { "optimization-warnings" , OptionValue::eTypeBoolean, false, true, NULL, NULL, "If true, warn when stopped in code that is optimized where stepping and variable availability may not behave as expected." },
{ NULL , OptionValue::eTypeInvalid, false, 0, NULL, NULL, NULL }
};
@@ -126,7 +127,8 @@
ePropertyPythonOSPluginPath,
ePropertyStopOnSharedLibraryEvents,
ePropertyDetachKeepsStopped,
- ePropertyMemCacheLineSize
+ ePropertyMemCacheLineSize,
+ ePropertyWarningOptimization
};
ProcessProperties::ProcessProperties (lldb_private::Process *process) :
@@ -263,6 +265,13 @@
m_collection_sp->SetPropertyAtIndexAsBoolean(NULL, idx, stop);
}
+bool
+ProcessProperties::GetWarningsOptimization () const
+{
+ const uint32_t idx = ePropertyWarningOptimization;
+ return m_collection_sp->GetPropertyAtIndexAsBoolean (NULL, idx, g_properties[idx].default_uint_value != 0);
+}
+
void
ProcessInstanceInfo::Dump (Stream &s, Platform *platform) const
{
@@ -755,6 +764,7 @@
m_last_broadcast_state (eStateInvalid),
m_destroy_in_process (false),
m_can_interpret_function_calls(false),
+ m_warnings_issued (),
m_can_jit(eCanJITDontKnow)
{
CheckInWithManager ();
@@ -6542,6 +6552,50 @@
}
}
+void
+Process::PrintWarning (uint64_t warning_type, void *repeat_key, const char *fmt, ...)
+{
+ bool print_warning = true;
+
+ StreamSP stream_sp = GetTarget().GetDebugger().GetAsyncOutputStream();
+ if (stream_sp.get() == nullptr)
+ return;
+ if (warning_type == eWarningsOptimization
+ && GetWarningsOptimization() == false)
+ {
+ return;
+ }
+
+ if (repeat_key != nullptr)
+ {
+ WarningsCollection::iterator it = m_warnings_issued.find (warning_type);
+ if (it == m_warnings_issued.end())
+ {
+ m_warnings_issued[warning_type] = WarningsPointerSet();
+ m_warnings_issued[warning_type].insert (repeat_key);
+ }
+ else
+ {
+ if (it->second.find (repeat_key) != it->second.end())
+ {
+ print_warning = false;
+ }
+ else
+ {
+ it->second.insert (repeat_key);
+ }
+ }
+ }
+
+ if (print_warning)
+ {
+ va_list args;
+ va_start (args, fmt);
+ stream_sp->PrintfVarArg (fmt, args);
+ va_end (args);
+ }
+}
+
ThreadCollectionSP
Process::GetHistoryThreads(lldb::addr_t addr)
{
diff --git a/lldb/source/Target/Thread.cpp b/lldb/source/Target/Thread.cpp
index b939aeb..0327fe7 100644
--- a/lldb/source/Target/Thread.cpp
+++ b/lldb/source/Target/Thread.cpp
@@ -360,12 +360,22 @@
BroadcastEvent(eBroadcastBitSelectedFrameChanged, new ThreadEventData (this->shared_from_this(), new_frame_id));
}
+lldb::StackFrameSP
+Thread::GetSelectedFrame()
+{
+ StackFrameListSP stack_frame_list_sp(GetStackFrameList());
+ StackFrameSP frame_sp = stack_frame_list_sp->GetFrameAtIndex (stack_frame_list_sp->GetSelectedFrameIndex());
+ FunctionOptimizationWarning (frame_sp.get());
+ return frame_sp;
+}
+
uint32_t
Thread::SetSelectedFrame (lldb_private::StackFrame *frame, bool broadcast)
{
uint32_t ret_value = GetStackFrameList()->SetSelectedFrame(frame);
if (broadcast)
BroadcastSelectedFrameChange(frame->GetStackID());
+ FunctionOptimizationWarning (frame);
return ret_value;
}
@@ -378,6 +388,7 @@
GetStackFrameList()->SetSelectedFrame(frame_sp.get());
if (broadcast)
BroadcastSelectedFrameChange(frame_sp->GetStackID());
+ FunctionOptimizationWarning (frame_sp.get());
return true;
}
else
@@ -403,6 +414,7 @@
bool show_frame_info = true;
bool show_source = !already_shown;
+ FunctionOptimizationWarning (frame_sp.get());
return frame_sp->GetStatus (output_stream, show_frame_info, show_source);
}
return false;
@@ -411,6 +423,22 @@
return false;
}
+void
+Thread::FunctionOptimizationWarning (StackFrame *frame)
+{
+ if (frame && frame->HasDebugInformation())
+ {
+ SymbolContext sc = frame->GetSymbolContext (eSymbolContextFunction | eSymbolContextCompUnit);
+ if (sc.function && sc.function->GetIsOptimized() == true && sc.comp_unit)
+ {
+ if (sc.line_entry.file.GetFilename().IsEmpty() == false)
+ {
+ GetProcess()->PrintWarning (Process::Warnings::eWarningsOptimization, sc.comp_unit, "%s was compiled with optimization - stepping may behave oddly; variables may not be available.\n", sc.line_entry.file.GetFilename().GetCString());
+ }
+ }
+ }
+}
+
lldb::StopInfoSP
Thread::GetStopInfo ()