Skip to content

Commit 30a0cf4

Browse files
committed
Merge remote-tracking branch 'origin/apple/stable/20200714' into swift/main
2 parents 9a14690 + 9cf602f commit 30a0cf4

File tree

26 files changed

+1122
-160
lines changed

26 files changed

+1122
-160
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,11 +1457,11 @@ def fno_pch_validate_input_files_content:
14571457
Group<f_Group>, Flags<[DriverOption]>;
14581458
def fpch_instantiate_templates:
14591459
Flag <["-"], "fpch-instantiate-templates">,
1460-
Group<f_Group>, Flags<[CC1Option]>,
1460+
Group<f_Group>, Flags<[CC1Option, CoreOption]>,
14611461
HelpText<"Instantiate templates already while building a PCH">;
14621462
def fno_pch_instantiate_templates:
14631463
Flag <["-"], "fno-pch-instantiate-templates">,
1464-
Group<f_Group>, Flags<[CC1Option]>;
1464+
Group<f_Group>, Flags<[CC1Option, CoreOption]>;
14651465
defm pch_codegen: OptInFFlag<"pch-codegen", "Generate ", "Do not generate ",
14661466
"code for uses of this PCH that assumes an explicit object file will be built for the PCH">;
14671467
defm pch_debuginfo: OptInFFlag<"pch-debuginfo", "Generate ", "Do not generate ",

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,11 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
11981198
if (YcArg && JA.getKind() >= Action::PrecompileJobClass &&
11991199
JA.getKind() <= Action::AssembleJobClass) {
12001200
CmdArgs.push_back(Args.MakeArgString("-building-pch-with-obj"));
1201-
CmdArgs.push_back(Args.MakeArgString("-fpch-instantiate-templates"));
1201+
// -fpch-instantiate-templates is the default when creating
1202+
// precomp using /Yc
1203+
if (Args.hasFlag(options::OPT_fpch_instantiate_templates,
1204+
options::OPT_fno_pch_instantiate_templates, true))
1205+
CmdArgs.push_back(Args.MakeArgString("-fpch-instantiate-templates"));
12021206
}
12031207
if (YcArg || YuArg) {
12041208
StringRef ThroughHeader = YcArg ? YcArg->getValue() : YuArg->getValue();
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// CL driver test cases
2+
// RUN: %clang_cl -### /Yc /Fpfoo.pch /Fofoo.obj -- %s 2>&1 | FileCheck --check-prefix=CLANG_CL_YC %s
3+
// RUN: %clang_cl -### /Yc /Fpfoo.pch /Fofoo.obj -fno-pch-instantiate-templates -- %s 2>&1 | FileCheck --check-prefix=CLANG_CL_YC_DISABLE %s
4+
5+
// CLANG_CL_YC: "-fpch-instantiate-templates"
6+
// CLANG_CL_YC_DISABLE-NOT: "-fpch-instantiate-templates"
7+
8+
// GCC driver test cases
9+
// RUN: %clang -### -x c-header %s -o %t/foo.pch 2>&1 | FileCheck -check-prefix=GCC_DEFAULT %s
10+
// RUN: %clang -### -x c-header %s -o %t/foo.pch -fpch-instantiate-templates 2>&1 | FileCheck -check-prefix=GCC_DEFAULT_ENABLE %s
11+
12+
// GCC_DEFAULT-NOT: "-fpch-instantiate-templates"
13+
// GCC_DEFAULT_ENABLE: "-fpch-instantiate-templates"

lldb/bindings/python/python-swigsafecast.swig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,10 @@ SBTypeToSWIGWrapper (lldb::SBSymbolContext* sym_ctx_sb)
161161
{
162162
return SWIG_NewPointerObj((void *) sym_ctx_sb, SWIGTYPE_p_lldb__SBSymbolContext, 0);
163163
}
164+
165+
template <>
166+
PyObject*
167+
SBTypeToSWIGWrapper (lldb::SBStream* stream_sb)
168+
{
169+
return SWIG_NewPointerObj((void *) stream_sb, SWIGTYPE_p_lldb__SBStream, 0);
170+
}

lldb/bindings/python/python-wrapper.swig

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,127 @@ LLDBSwigPythonCallBreakpointResolver
468468
return ret_val;
469469
}
470470

471+
SWIGEXPORT void *
472+
LLDBSwigPythonCreateScriptedStopHook
473+
(
474+
lldb::TargetSP target_sp,
475+
const char *python_class_name,
476+
const char *session_dictionary_name,
477+
lldb_private::StructuredDataImpl *args_impl,
478+
Status &error
479+
)
480+
{
481+
if (python_class_name == NULL || python_class_name[0] == '\0') {
482+
error.SetErrorString("Empty class name.");
483+
Py_RETURN_NONE;
484+
}
485+
if (!session_dictionary_name) {
486+
error.SetErrorString("No session dictionary");
487+
Py_RETURN_NONE;
488+
}
489+
490+
PyErr_Cleaner py_err_cleaner(true);
491+
492+
auto dict =
493+
PythonModule::MainModule().ResolveName<PythonDictionary>(
494+
session_dictionary_name);
495+
auto pfunc =
496+
PythonObject::ResolveNameWithDictionary<PythonCallable>(
497+
python_class_name, dict);
498+
499+
if (!pfunc.IsAllocated()) {
500+
error.SetErrorStringWithFormat("Could not find class: %s.",
501+
python_class_name);
502+
return nullptr;
503+
}
504+
505+
lldb::SBTarget *target_val
506+
= new lldb::SBTarget(target_sp);
507+
508+
PythonObject target_arg(PyRefType::Owned, SBTypeToSWIGWrapper(target_val));
509+
510+
lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl);
511+
PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(args_value));
512+
513+
PythonObject result = pfunc(target_arg, args_arg, dict);
514+
515+
if (result.IsAllocated())
516+
{
517+
// Check that the handle_stop callback is defined:
518+
auto callback_func = result.ResolveName<PythonCallable>("handle_stop");
519+
if (callback_func.IsAllocated()) {
520+
if (auto args_info = callback_func.GetArgInfo()) {
521+
size_t num_args = (*args_info).max_positional_args;
522+
if (num_args != 2) {
523+
error.SetErrorStringWithFormat("Wrong number of args for "
524+
"handle_stop callback, should be 2 (excluding self), got: %d",
525+
num_args);
526+
Py_RETURN_NONE;
527+
} else
528+
return result.release();
529+
} else {
530+
error.SetErrorString("Couldn't get num arguments for handle_stop "
531+
"callback.");
532+
Py_RETURN_NONE;
533+
}
534+
return result.release();
535+
}
536+
else {
537+
error.SetErrorStringWithFormat("Class \"%s\" is missing the required "
538+
"handle_stop callback.",
539+
python_class_name);
540+
result.release();
541+
}
542+
}
543+
Py_RETURN_NONE;
544+
}
545+
546+
SWIGEXPORT bool
547+
LLDBSwigPythonStopHookCallHandleStop
548+
(
549+
void *implementor,
550+
lldb::ExecutionContextRefSP exc_ctx_sp,
551+
lldb::StreamSP stream
552+
)
553+
{
554+
// handle_stop will return a bool with the meaning "should_stop"...
555+
// If you return nothing we'll assume we are going to stop.
556+
// Also any errors should return true, since we should stop on error.
557+
558+
PyErr_Cleaner py_err_cleaner(false);
559+
PythonObject self(PyRefType::Borrowed, static_cast<PyObject*>(implementor));
560+
auto pfunc = self.ResolveName<PythonCallable>("handle_stop");
561+
562+
if (!pfunc.IsAllocated())
563+
return true;
564+
565+
PythonObject result;
566+
lldb::SBExecutionContext sb_exc_ctx(exc_ctx_sp);
567+
PythonObject exc_ctx_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_exc_ctx));
568+
lldb::SBStream sb_stream;
569+
PythonObject sb_stream_arg(PyRefType::Owned,
570+
SBTypeToSWIGWrapper(sb_stream));
571+
result = pfunc(exc_ctx_arg, sb_stream_arg);
572+
573+
if (PyErr_Occurred())
574+
{
575+
stream->PutCString("Python error occurred handling stop-hook.");
576+
PyErr_Print();
577+
PyErr_Clear();
578+
return true;
579+
}
580+
581+
// Now add the result to the output stream. SBStream only
582+
// makes an internally help StreamString which I can't interpose, so I
583+
// have to copy it over here.
584+
stream->PutCString(sb_stream.GetData());
585+
586+
if (result.get() == Py_False)
587+
return false;
588+
else
589+
return true;
590+
}
591+
471592
// wrapper that calls an optional instance member of an object taking no arguments
472593
static PyObject*
473594
LLDBSwigPython_CallOptionalMember

lldb/docs/use/python-reference.rst

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,3 +819,49 @@ When the program is stopped at the beginning of the 'read' function in libc, we
819819
frame #0: 0x00007fff06013ca0 libsystem_kernel.dylib`read
820820
(lldb) frame variable
821821
(int) fd = 3
822+
823+
Writing Target Stop-Hooks in Python:
824+
------------------------------------
825+
826+
Stop hooks fire whenever the process stops just before control is returned to the
827+
user. Stop hooks can either be a set of lldb command-line commands, or can
828+
be implemented by a suitably defined Python class. The Python based stop-hooks
829+
can also be passed as set of -key -value pairs when they are added, and those
830+
will get packaged up into a SBStructuredData Dictionary and passed to the
831+
constructor of the Python object managing the stop hook. This allows for
832+
parametrization of the stop hooks.
833+
834+
To add a Python-based stop hook, first define a class with the following methods:
835+
836+
+--------------------+---------------------------------------+------------------------------------------------------------------------------------------------------------------+
837+
| Name | Arguments | Description |
838+
+--------------------+---------------------------------------+------------------------------------------------------------------------------------------------------------------+
839+
| **__init__** | **target: lldb.SBTarget** | This is the constructor for the new stop-hook. |
840+
| | **extra_args: lldb.SBStructuredData** | |
841+
| | | |
842+
| | | **target** is the SBTarget to which the stop hook is added. |
843+
| | | |
844+
| | | **extra_args** is an SBStructuredData object that the user can pass in when creating instances of this |
845+
| | | breakpoint. It is not required, but allows for reuse of stop-hook classes. |
846+
+--------------------+---------------------------------------+------------------------------------------------------------------------------------------------------------------+
847+
| **handle_stop** | **exe_ctx: lldb.SBExecutionContext** | This is the called when the target stops. |
848+
| | **stream: lldb.SBStream** | |
849+
| | | **exe_ctx** argument will be filled with the current stop point for which the stop hook is |
850+
| | | being evaluated. |
851+
| | | |
852+
| | | **stream** an lldb.SBStream, anything written to this stream will be written to the debugger console. |
853+
| | | |
854+
| | | The return value is a "Should Stop" vote from this thread. If the method returns either True or no return |
855+
| | | this thread votes to stop. If it returns False, then the thread votes to continue after all the stop-hooks |
856+
| | | are evaluated. |
857+
| | | Note, the --auto-continue flag to 'target stop-hook add' overrides a True return value from the method. |
858+
+--------------------+---------------------------------------+------------------------------------------------------------------------------------------------------------------+
859+
860+
To use this class in lldb, run the command:
861+
862+
::
863+
864+
(lldb) command script import MyModule.py
865+
(lldb) target stop-hook add -P MyModule.MyStopHook -k first -v 1 -k second -v 2
866+
867+
where MyModule.py is the file containing the class definition MyStopHook.

lldb/include/lldb/Interpreter/ScriptInterpreter.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,23 @@ class ScriptInterpreter : public PluginInterface {
298298
return lldb::eSearchDepthModule;
299299
}
300300

301+
virtual StructuredData::GenericSP
302+
CreateScriptedStopHook(lldb::TargetSP target_sp, const char *class_name,
303+
StructuredDataImpl *args_data, Status &error) {
304+
error.SetErrorString("Creating scripted stop-hooks with the current "
305+
"script interpreter is not supported.");
306+
return StructuredData::GenericSP();
307+
}
308+
309+
// This dispatches to the handle_stop method of the stop-hook class. It
310+
// returns a "should_stop" bool.
311+
virtual bool
312+
ScriptedStopHookHandleStop(StructuredData::GenericSP implementor_sp,
313+
ExecutionContext &exc_ctx,
314+
lldb::StreamSP stream_sp) {
315+
return true;
316+
}
317+
301318
virtual StructuredData::ObjectSP
302319
LoadPluginModule(const FileSpec &file_spec, lldb_private::Status &error) {
303320
return StructuredData::ObjectSP();

lldb/include/lldb/Symbol/SymbolContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ class SymbolContextSpecifier {
340340

341341
void Clear();
342342

343-
bool SymbolContextMatches(SymbolContext &sc);
343+
bool SymbolContextMatches(const SymbolContext &sc);
344344

345345
bool AddressMatches(lldb::addr_t addr);
346346

0 commit comments

Comments
 (0)