lldb::SBListener GetListener();
void HandleProcessEvent(const lldb::SBProcess &process,
- const lldb::SBEvent &event, FILE *out, FILE *err);
+ const lldb::SBEvent &event, FILE *out,
+ FILE *err); // DEPRECATED
+
+ void HandleProcessEvent(const lldb::SBProcess &process,
+ const lldb::SBEvent &event, SBFile out, SBFile err);
+
+ void HandleProcessEvent(const lldb::SBProcess &process,
+ const lldb::SBEvent &event, FileSP out, FileSP err);
lldb::SBTarget CreateTarget(const char *filename, const char *target_triple,
const char *platform_name,
class LLDB_API SBFile {
friend class SBDebugger;
friend class SBCommandReturnObject;
+ friend class SBProcess;
public:
SBFile();
void ReportEventState(const lldb::SBEvent &event, FILE *out) const;
+ void ReportEventState(const lldb::SBEvent &event, SBFile file) const;
+
+ void ReportEventState(const lldb::SBEvent &event, FileSP file) const;
+
void AppendEventStateReport(const lldb::SBEvent &event,
lldb::SBCommandReturnObject &result);
obj.GetCommandInterpreter()
obj.HandleCommand("nothing here")
listener = obj.GetListener()
- obj.HandleProcessEvent(lldb.SBProcess(), lldb.SBEvent(), None, None)
+ try:
+ obj.HandleProcessEvent(lldb.SBProcess(), lldb.SBEvent(), None, None)
+ except Exception:
+ pass
obj.CreateTargetWithFileAndTargetTriple("a.out", "A-B-C")
obj.CreateTargetWithFileAndArch("b.out", "arm")
obj.CreateTarget("c.out")
obj.GetSTDOUT(6)
obj.GetSTDERR(6)
event = lldb.SBEvent()
- obj.ReportEventState(event, None)
+ try:
+ obj.ReportEventState(event, None)
+ except Exception:
+ pass
obj.AppendEventStateReport(event, lldb.SBCommandReturnObject())
error = lldb.SBError()
obj.RemoteAttachToProcessWithID(123, error)
void
HandleProcessEvent (const lldb::SBProcess &process,
const lldb::SBEvent &event,
- FILE *out,
- FILE *err);
+ SBFile out,
+ SBFile err);
+
+ void
+ HandleProcessEvent (const lldb::SBProcess &process,
+ const lldb::SBEvent &event,
+ FileSP BORROWED,
+ FileSP BORROWED);
lldb::SBTarget
CreateTarget (const char *filename,
GetAsyncProfileData(char *dst, size_t dst_len) const;
void
- ReportEventState (const lldb::SBEvent &event, FILE *out) const;
+ ReportEventState (const lldb::SBEvent &event, SBFile out) const;
+
+ void
+ ReportEventState (const lldb::SBEvent &event, FileSP BORROWED) const;
void
AppendEventStateReport (const lldb::SBEvent &event, lldb::SBCommandReturnObject &result);
while (lldb_listener_sp->GetEventForBroadcaster(
process_sp.get(), event_sp, std::chrono::seconds(0))) {
SBEvent event(event_sp);
- HandleProcessEvent(process, event, GetOutputFileHandle(),
- GetErrorFileHandle());
+ HandleProcessEvent(process, event, GetOutputFile(), GetErrorFile());
}
}
}
}
void SBDebugger::HandleProcessEvent(const SBProcess &process,
+ const SBEvent &event, SBFile out,
+ SBFile err) {
+ LLDB_RECORD_METHOD(
+ void, SBDebugger, HandleProcessEvent,
+ (const lldb::SBProcess &, const lldb::SBEvent &, SBFile, SBFile), process,
+ event, out, err);
+
+ return HandleProcessEvent(process, event, out.m_opaque_sp, err.m_opaque_sp);
+}
+
+void SBDebugger::HandleProcessEvent(const SBProcess &process,
const SBEvent &event, FILE *out,
FILE *err) {
LLDB_RECORD_METHOD(
(const lldb::SBProcess &, const lldb::SBEvent &, FILE *, FILE *), process,
event, out, err);
+ FileSP outfile = std::make_shared<NativeFile>(out, false);
+ FileSP errfile = std::make_shared<NativeFile>(err, false);
+ return HandleProcessEvent(process, event, outfile, errfile);
+}
+
+void SBDebugger::HandleProcessEvent(const SBProcess &process,
+ const SBEvent &event, FileSP out_sp,
+ FileSP err_sp) {
+
+ LLDB_RECORD_METHOD(
+ void, SBDebugger, HandleProcessEvent,
+ (const lldb::SBProcess &, const lldb::SBEvent &, FileSP, FileSP), process,
+ event, out_sp, err_sp);
+
if (!process.IsValid())
return;
(Process::eBroadcastBitSTDOUT | Process::eBroadcastBitStateChanged)) {
// Drain stdout when we stop just in case we have any bytes
while ((len = process.GetSTDOUT(stdio_buffer, sizeof(stdio_buffer))) > 0)
- if (out != nullptr)
- ::fwrite(stdio_buffer, 1, len, out);
+ if (out_sp)
+ out_sp->Write(stdio_buffer, len);
}
if (event_type &
(Process::eBroadcastBitSTDERR | Process::eBroadcastBitStateChanged)) {
// Drain stderr when we stop just in case we have any bytes
while ((len = process.GetSTDERR(stdio_buffer, sizeof(stdio_buffer))) > 0)
- if (err != nullptr)
- ::fwrite(stdio_buffer, 1, len, err);
+ if (err_sp)
+ err_sp->Write(stdio_buffer, len);
}
if (event_type & Process::eBroadcastBitStateChanged) {
bool is_stopped = StateIsStoppedState(event_state);
if (!is_stopped)
- process.ReportEventState(event, out);
+ process.ReportEventState(event, out_sp);
}
}
LLDB_REGISTER_METHOD(
void, SBDebugger, HandleProcessEvent,
(const lldb::SBProcess &, const lldb::SBEvent &, FILE *, FILE *));
+ LLDB_REGISTER_METHOD(
+ void, SBDebugger, HandleProcessEvent,
+ (const lldb::SBProcess &, const lldb::SBEvent &, SBFile, SBFile));
+ LLDB_REGISTER_METHOD(
+ void, SBDebugger, HandleProcessEvent,
+ (const lldb::SBProcess &, const lldb::SBEvent &, FileSP, FileSP));
LLDB_REGISTER_METHOD(lldb::SBSourceManager, SBDebugger, GetSourceManager, ());
LLDB_REGISTER_STATIC_METHOD(bool, SBDebugger, SetDefaultArchitecture,
(const char *));
#include "lldb/Utility/State.h"
#include "lldb/Utility/Stream.h"
-
#include "lldb/API/SBBroadcaster.h"
#include "lldb/API/SBCommandReturnObject.h"
#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBEvent.h"
+#include "lldb/API/SBFile.h"
#include "lldb/API/SBFileSpec.h"
#include "lldb/API/SBMemoryRegionInfo.h"
#include "lldb/API/SBMemoryRegionInfoList.h"
return LLDB_RECORD_RESULT(trace_instance);
}
+void SBProcess::ReportEventState(const SBEvent &event, SBFile out) const {
+ LLDB_RECORD_METHOD_CONST(void, SBProcess, ReportEventState,
+ (const SBEvent &, SBFile), event, out);
+
+ return ReportEventState(event, out.m_opaque_sp);
+}
+
void SBProcess::ReportEventState(const SBEvent &event, FILE *out) const {
LLDB_RECORD_METHOD_CONST(void, SBProcess, ReportEventState,
(const lldb::SBEvent &, FILE *), event, out);
+ FileSP outfile = std::make_shared<NativeFile>(out, false);
+ return ReportEventState(event, outfile);
+}
+
+void SBProcess::ReportEventState(const SBEvent &event, FileSP out) const {
- if (out == nullptr)
+ LLDB_RECORD_METHOD_CONST(void, SBProcess, ReportEventState,
+ (const SBEvent &, FileSP), event, out);
+
+ if (!out || !out->IsValid())
return;
ProcessSP process_sp(GetSP());
if (process_sp) {
+ StreamFile stream(out);
const StateType event_state = SBProcess::GetStateFromEvent(event);
- char message[1024];
- int message_len = ::snprintf(
- message, sizeof(message), "Process %" PRIu64 " %s\n",
+ stream.Printf("Process %" PRIu64 " %s\n",
process_sp->GetID(), SBDebugger::StateAsCString(event_state));
-
- if (message_len > 0)
- ::fwrite(message, 1, message_len, out);
}
}
(lldb::SBTraceOptions &, lldb::SBError &));
LLDB_REGISTER_METHOD_CONST(void, SBProcess, ReportEventState,
(const lldb::SBEvent &, FILE *));
+ LLDB_REGISTER_METHOD_CONST(void, SBProcess, ReportEventState,
+ (const lldb::SBEvent &, FileSP));
+ LLDB_REGISTER_METHOD_CONST(void, SBProcess, ReportEventState,
+ (const lldb::SBEvent &, SBFile));
LLDB_REGISTER_METHOD(
void, SBProcess, AppendEventStateReport,
(const lldb::SBEvent &, lldb::SBCommandReturnObject &));