Skip to content

Commit 0bb10e4

Browse files
authored
Merge pull request #1917 from apple/merge-bastille-into-main
Merge bastille into main
2 parents 9a14690 + adb227f commit 0bb10e4

File tree

28 files changed

+1362
-161
lines changed

28 files changed

+1362
-161
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

0 commit comments

Comments
 (0)