Skip to content

Merge bastille into main #1917

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Oct 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -1457,11 +1457,11 @@ def fno_pch_validate_input_files_content:
Group<f_Group>, Flags<[DriverOption]>;
def fpch_instantiate_templates:
Flag <["-"], "fpch-instantiate-templates">,
Group<f_Group>, Flags<[CC1Option]>,
Group<f_Group>, Flags<[CC1Option, CoreOption]>,
HelpText<"Instantiate templates already while building a PCH">;
def fno_pch_instantiate_templates:
Flag <["-"], "fno-pch-instantiate-templates">,
Group<f_Group>, Flags<[CC1Option]>;
Group<f_Group>, Flags<[CC1Option, CoreOption]>;
defm pch_codegen: OptInFFlag<"pch-codegen", "Generate ", "Do not generate ",
"code for uses of this PCH that assumes an explicit object file will be built for the PCH">;
defm pch_debuginfo: OptInFFlag<"pch-debuginfo", "Generate ", "Do not generate ",
Expand Down
6 changes: 5 additions & 1 deletion clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1198,7 +1198,11 @@ void Clang::AddPreprocessingOptions(Compilation &C, const JobAction &JA,
if (YcArg && JA.getKind() >= Action::PrecompileJobClass &&
JA.getKind() <= Action::AssembleJobClass) {
CmdArgs.push_back(Args.MakeArgString("-building-pch-with-obj"));
CmdArgs.push_back(Args.MakeArgString("-fpch-instantiate-templates"));
// -fpch-instantiate-templates is the default when creating
// precomp using /Yc
if (Args.hasFlag(options::OPT_fpch_instantiate_templates,
options::OPT_fno_pch_instantiate_templates, true))
CmdArgs.push_back(Args.MakeArgString("-fpch-instantiate-templates"));
}
if (YcArg || YuArg) {
StringRef ThroughHeader = YcArg ? YcArg->getValue() : YuArg->getValue();
Expand Down
13 changes: 13 additions & 0 deletions clang/test/Driver/pch-instantiate-templates.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// CL driver test cases
// RUN: %clang_cl -### /Yc /Fpfoo.pch /Fofoo.obj -- %s 2>&1 | FileCheck --check-prefix=CLANG_CL_YC %s
// RUN: %clang_cl -### /Yc /Fpfoo.pch /Fofoo.obj -fno-pch-instantiate-templates -- %s 2>&1 | FileCheck --check-prefix=CLANG_CL_YC_DISABLE %s

// CLANG_CL_YC: "-fpch-instantiate-templates"
// CLANG_CL_YC_DISABLE-NOT: "-fpch-instantiate-templates"

// GCC driver test cases
// RUN: %clang -### -x c-header %s -o %t/foo.pch 2>&1 | FileCheck -check-prefix=GCC_DEFAULT %s
// RUN: %clang -### -x c-header %s -o %t/foo.pch -fpch-instantiate-templates 2>&1 | FileCheck -check-prefix=GCC_DEFAULT_ENABLE %s

// GCC_DEFAULT-NOT: "-fpch-instantiate-templates"
// GCC_DEFAULT_ENABLE: "-fpch-instantiate-templates"
7 changes: 7 additions & 0 deletions lldb/bindings/python/python-swigsafecast.swig
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,10 @@ SBTypeToSWIGWrapper (lldb::SBSymbolContext* sym_ctx_sb)
{
return SWIG_NewPointerObj((void *) sym_ctx_sb, SWIGTYPE_p_lldb__SBSymbolContext, 0);
}

template <>
PyObject*
SBTypeToSWIGWrapper (lldb::SBStream* stream_sb)
{
return SWIG_NewPointerObj((void *) stream_sb, SWIGTYPE_p_lldb__SBStream, 0);
}
121 changes: 121 additions & 0 deletions lldb/bindings/python/python-wrapper.swig
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,127 @@ LLDBSwigPythonCallBreakpointResolver
return ret_val;
}

SWIGEXPORT void *
LLDBSwigPythonCreateScriptedStopHook
(
lldb::TargetSP target_sp,
const char *python_class_name,
const char *session_dictionary_name,
lldb_private::StructuredDataImpl *args_impl,
Status &error
)
{
if (python_class_name == NULL || python_class_name[0] == '\0') {
error.SetErrorString("Empty class name.");
Py_RETURN_NONE;
}
if (!session_dictionary_name) {
error.SetErrorString("No session dictionary");
Py_RETURN_NONE;
}

PyErr_Cleaner py_err_cleaner(true);

auto dict =
PythonModule::MainModule().ResolveName<PythonDictionary>(
session_dictionary_name);
auto pfunc =
PythonObject::ResolveNameWithDictionary<PythonCallable>(
python_class_name, dict);

if (!pfunc.IsAllocated()) {
error.SetErrorStringWithFormat("Could not find class: %s.",
python_class_name);
return nullptr;
}

lldb::SBTarget *target_val
= new lldb::SBTarget(target_sp);

PythonObject target_arg(PyRefType::Owned, SBTypeToSWIGWrapper(target_val));

lldb::SBStructuredData *args_value = new lldb::SBStructuredData(args_impl);
PythonObject args_arg(PyRefType::Owned, SBTypeToSWIGWrapper(args_value));

PythonObject result = pfunc(target_arg, args_arg, dict);

if (result.IsAllocated())
{
// Check that the handle_stop callback is defined:
auto callback_func = result.ResolveName<PythonCallable>("handle_stop");
if (callback_func.IsAllocated()) {
if (auto args_info = callback_func.GetArgInfo()) {
size_t num_args = (*args_info).max_positional_args;
if (num_args != 2) {
error.SetErrorStringWithFormat("Wrong number of args for "
"handle_stop callback, should be 2 (excluding self), got: %d",
num_args);
Py_RETURN_NONE;
} else
return result.release();
} else {
error.SetErrorString("Couldn't get num arguments for handle_stop "
"callback.");
Py_RETURN_NONE;
}
return result.release();
}
else {
error.SetErrorStringWithFormat("Class \"%s\" is missing the required "
"handle_stop callback.",
python_class_name);
result.release();
}
}
Py_RETURN_NONE;
}

SWIGEXPORT bool
LLDBSwigPythonStopHookCallHandleStop
(
void *implementor,
lldb::ExecutionContextRefSP exc_ctx_sp,
lldb::StreamSP stream
)
{
// handle_stop will return a bool with the meaning "should_stop"...
// If you return nothing we'll assume we are going to stop.
// Also any errors should return true, since we should stop on error.

PyErr_Cleaner py_err_cleaner(false);
PythonObject self(PyRefType::Borrowed, static_cast<PyObject*>(implementor));
auto pfunc = self.ResolveName<PythonCallable>("handle_stop");

if (!pfunc.IsAllocated())
return true;

PythonObject result;
lldb::SBExecutionContext sb_exc_ctx(exc_ctx_sp);
PythonObject exc_ctx_arg(PyRefType::Owned, SBTypeToSWIGWrapper(sb_exc_ctx));
lldb::SBStream sb_stream;
PythonObject sb_stream_arg(PyRefType::Owned,
SBTypeToSWIGWrapper(sb_stream));
result = pfunc(exc_ctx_arg, sb_stream_arg);

if (PyErr_Occurred())
{
stream->PutCString("Python error occurred handling stop-hook.");
PyErr_Print();
PyErr_Clear();
return true;
}

// Now add the result to the output stream. SBStream only
// makes an internally help StreamString which I can't interpose, so I
// have to copy it over here.
stream->PutCString(sb_stream.GetData());

if (result.get() == Py_False)
return false;
else
return true;
}

// wrapper that calls an optional instance member of an object taking no arguments
static PyObject*
LLDBSwigPython_CallOptionalMember
Expand Down
Loading