2010-06-09 00:52:24 +08:00
|
|
|
//===-- Driver.cpp ----------------------------------------------*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2010-06-09 00:52:24 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Driver.h"
|
|
|
|
|
2010-06-09 17:50:17 +08:00
|
|
|
#include "lldb/API/SBCommandInterpreter.h"
|
2020-05-01 04:28:42 +08:00
|
|
|
#include "lldb/API/SBCommandInterpreterRunOptions.h"
|
2010-06-09 17:50:17 +08:00
|
|
|
#include "lldb/API/SBCommandReturnObject.h"
|
|
|
|
#include "lldb/API/SBDebugger.h"
|
2019-10-10 05:50:49 +08:00
|
|
|
#include "lldb/API/SBFile.h"
|
2010-06-09 17:50:17 +08:00
|
|
|
#include "lldb/API/SBHostOS.h"
|
2015-10-20 08:23:46 +08:00
|
|
|
#include "lldb/API/SBLanguageRuntime.h"
|
2019-02-22 06:26:16 +08:00
|
|
|
#include "lldb/API/SBReproducer.h"
|
2011-02-19 10:53:09 +08:00
|
|
|
#include "lldb/API/SBStream.h"
|
2016-02-19 08:05:17 +08:00
|
|
|
#include "lldb/API/SBStringList.h"
|
[lldb] make it easier to find LLDB's python
It is surprisingly difficult to write a simple python script that
can reliably `import lldb` without failing, or crashing. I'm
currently resorting to convolutions like this:
def find_lldb(may_reexec=False):
if prefix := os.environ.get('LLDB_PYTHON_PREFIX'):
if os.path.realpath(prefix) != os.path.realpath(sys.prefix):
raise Exception("cannot import lldb.\n"
f" sys.prefix should be: {prefix}\n"
f" but it is: {sys.prefix}")
else:
line1, line2 = subprocess.run(
['lldb', '-x', '-b', '-o', 'script print(sys.prefix)'],
encoding='utf8', stdout=subprocess.PIPE,
check=True).stdout.strip().splitlines()
assert line1.strip() == '(lldb) script print(sys.prefix)'
prefix = line2.strip()
os.environ['LLDB_PYTHON_PREFIX'] = prefix
if sys.prefix != prefix:
if not may_reexec:
raise Exception(
"cannot import lldb.\n" +
f" This python, at {sys.prefix}\n"
f" does not math LLDB's python at {prefix}")
os.environ['LLDB_PYTHON_PREFIX'] = prefix
python_exe = os.path.join(prefix, 'bin', 'python3')
os.execl(python_exe, python_exe, *sys.argv)
lldb_path = subprocess.run(['lldb', '-P'],
check=True, stdout=subprocess.PIPE,
encoding='utf8').stdout.strip()
sys.path = [lldb_path] + sys.path
This patch aims to replace all that with:
#!/usr/bin/env lldb-python
import lldb
...
... by adding the following features:
* new command line option: --print-script-interpreter-info. This
prints language-specific information about the script interpreter
in JSON format.
* new tool (unix only): lldb-python which finds python and exec's it.
Reviewed By: JDevlieghere
Differential Revision: https://reviews.llvm.org/D112973
2021-11-11 02:33:33 +08:00
|
|
|
#include "lldb/API/SBStructuredData.h"
|
2018-11-28 05:00:32 +08:00
|
|
|
|
2018-07-17 18:04:19 +08:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2018-11-29 06:39:17 +08:00
|
|
|
#include "llvm/Support/Format.h"
|
2019-10-11 16:44:51 +08:00
|
|
|
#include "llvm/Support/InitLLVM.h"
|
2018-11-28 05:00:32 +08:00
|
|
|
#include "llvm/Support/Path.h"
|
2018-07-17 18:04:19 +08:00
|
|
|
#include "llvm/Support/Signals.h"
|
2018-11-29 06:39:17 +08:00
|
|
|
#include "llvm/Support/WithColor.h"
|
2018-11-28 05:00:32 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <atomic>
|
|
|
|
#include <bitset>
|
2021-07-13 18:37:53 +08:00
|
|
|
#include <clocale>
|
2018-11-28 05:00:32 +08:00
|
|
|
#include <csignal>
|
|
|
|
#include <string>
|
2016-03-23 01:58:09 +08:00
|
|
|
#include <thread>
|
2018-09-29 01:58:16 +08:00
|
|
|
#include <utility>
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2021-05-26 18:19:37 +08:00
|
|
|
#include <climits>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
2018-11-28 05:00:32 +08:00
|
|
|
#include <fcntl.h>
|
|
|
|
|
2014-09-15 23:17:13 +08:00
|
|
|
#if !defined(__APPLE__)
|
2014-09-12 04:26:49 +08:00
|
|
|
#include "llvm/Support/DataTypes.h"
|
2014-09-15 23:17:13 +08:00
|
|
|
#endif
|
2014-09-12 04:26:49 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
using namespace lldb;
|
2018-11-28 05:00:32 +08:00
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
enum ID {
|
|
|
|
OPT_INVALID = 0, // This is not an option ID.
|
|
|
|
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
|
|
|
|
HELPTEXT, METAVAR, VALUES) \
|
|
|
|
OPT_##ID,
|
|
|
|
#include "Options.inc"
|
|
|
|
#undef OPTION
|
|
|
|
};
|
|
|
|
|
|
|
|
#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE;
|
|
|
|
#include "Options.inc"
|
|
|
|
#undef PREFIX
|
|
|
|
|
2019-01-05 08:01:04 +08:00
|
|
|
const opt::OptTable::Info InfoTable[] = {
|
2018-11-28 05:00:32 +08:00
|
|
|
#define OPTION(PREFIX, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
|
|
|
|
HELPTEXT, METAVAR, VALUES) \
|
|
|
|
{ \
|
|
|
|
PREFIX, NAME, HELPTEXT, \
|
|
|
|
METAVAR, OPT_##ID, opt::Option::KIND##Class, \
|
|
|
|
PARAM, FLAGS, OPT_##GROUP, \
|
|
|
|
OPT_##ALIAS, ALIASARGS, VALUES},
|
|
|
|
#include "Options.inc"
|
|
|
|
#undef OPTION
|
|
|
|
};
|
|
|
|
|
|
|
|
class LLDBOptTable : public opt::OptTable {
|
|
|
|
public:
|
|
|
|
LLDBOptTable() : OptTable(InfoTable) {}
|
|
|
|
};
|
|
|
|
} // namespace
|
2010-06-09 00:52:24 +08:00
|
|
|
|
|
|
|
static void reset_stdin_termios();
|
2012-02-03 03:28:31 +08:00
|
|
|
static bool g_old_stdin_termios_is_valid = false;
|
2010-06-09 00:52:24 +08:00
|
|
|
static struct termios g_old_stdin_termios;
|
|
|
|
|
2022-03-01 05:59:19 +08:00
|
|
|
static bool disable_color(const raw_ostream &OS) { return false; }
|
|
|
|
|
2019-01-05 08:01:04 +08:00
|
|
|
static Driver *g_driver = nullptr;
|
2010-09-10 01:45:09 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
// In the Driver::MainLoop, we change the terminal settings. This function is
|
|
|
|
// added as an atexit handler to make sure we clean them up.
|
|
|
|
static void reset_stdin_termios() {
|
2012-02-03 03:28:31 +08:00
|
|
|
if (g_old_stdin_termios_is_valid) {
|
|
|
|
g_old_stdin_termios_is_valid = false;
|
|
|
|
::tcsetattr(STDIN_FILENO, TCSANOW, &g_old_stdin_termios);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Driver::Driver()
|
2019-01-05 08:01:04 +08:00
|
|
|
: SBBroadcaster("Driver"), m_debugger(SBDebugger::Create(false)) {
|
2011-05-29 12:06:55 +08:00
|
|
|
// We want to be able to handle CTRL+D in the terminal to have it terminate
|
|
|
|
// certain input
|
|
|
|
m_debugger.SetCloseInputOnEOF(false);
|
2010-11-20 04:47:54 +08:00
|
|
|
g_driver = this;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2020-11-10 08:36:03 +08:00
|
|
|
Driver::~Driver() {
|
|
|
|
SBDebugger::Destroy(m_debugger);
|
|
|
|
g_driver = nullptr;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2018-11-28 05:00:32 +08:00
|
|
|
void Driver::OptionData::AddInitialCommand(std::string command,
|
2015-07-08 08:59:59 +08:00
|
|
|
CommandPlacement placement,
|
2010-06-23 09:19:29 +08:00
|
|
|
bool is_file, SBError &error) {
|
|
|
|
std::vector<InitialCmdEntry> *command_set;
|
2014-11-19 09:28:13 +08:00
|
|
|
switch (placement) {
|
2010-06-23 09:19:29 +08:00
|
|
|
case eCommandPlacementBeforeFile:
|
2010-12-09 06:23:24 +08:00
|
|
|
command_set = &(m_initial_commands);
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2014-11-19 09:28:13 +08:00
|
|
|
case eCommandPlacementAfterFile:
|
2013-09-14 08:20:24 +08:00
|
|
|
command_set = &(m_after_file_commands);
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2010-12-09 06:23:24 +08:00
|
|
|
case eCommandPlacementAfterCrash:
|
|
|
|
command_set = &(m_after_crash_commands);
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-09-14 08:20:24 +08:00
|
|
|
if (is_file) {
|
2018-11-28 05:00:32 +08:00
|
|
|
SBFileSpec file(command.c_str());
|
2010-12-09 06:23:24 +08:00
|
|
|
if (file.Exists())
|
2019-05-07 04:45:31 +08:00
|
|
|
command_set->push_back(InitialCmdEntry(command, is_file));
|
2010-12-09 06:23:24 +08:00
|
|
|
else if (file.ResolveExecutableLocation()) {
|
|
|
|
char final_path[PATH_MAX];
|
2010-06-23 09:19:29 +08:00
|
|
|
file.GetPath(final_path, sizeof(final_path));
|
2019-05-07 04:45:31 +08:00
|
|
|
command_set->push_back(InitialCmdEntry(final_path, is_file));
|
2016-09-07 04:57:50 +08:00
|
|
|
} else
|
2010-12-09 06:23:24 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
2018-11-28 05:00:32 +08:00
|
|
|
"file specified in --source (-s) option doesn't exist: '%s'",
|
|
|
|
command.c_str());
|
2016-09-07 04:57:50 +08:00
|
|
|
} else
|
2019-05-07 04:45:31 +08:00
|
|
|
command_set->push_back(InitialCmdEntry(command, is_file));
|
2010-06-23 09:19:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Driver::WriteCommandsForSourcing(CommandPlacement placement,
|
|
|
|
SBStream &strm) {
|
|
|
|
std::vector<OptionData::InitialCmdEntry> *command_set;
|
2014-11-19 09:28:13 +08:00
|
|
|
switch (placement) {
|
|
|
|
case eCommandPlacementBeforeFile:
|
|
|
|
command_set = &m_option_data.m_initial_commands;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2014-11-19 09:28:13 +08:00
|
|
|
case eCommandPlacementAfterFile:
|
|
|
|
command_set = &m_option_data.m_after_file_commands;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
2014-11-19 09:28:13 +08:00
|
|
|
case eCommandPlacementAfterCrash:
|
|
|
|
command_set = &m_option_data.m_after_crash_commands;
|
2016-09-07 04:57:50 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-11-22 09:33:22 +08:00
|
|
|
for (const auto &command_entry : *command_set) {
|
2010-06-23 09:19:29 +08:00
|
|
|
const char *command = command_entry.contents.c_str();
|
2014-11-22 09:33:22 +08:00
|
|
|
if (command_entry.is_file) {
|
|
|
|
bool source_quietly =
|
2010-06-23 09:19:29 +08:00
|
|
|
m_option_data.m_source_quietly || command_entry.source_quietly;
|
2019-01-05 08:01:04 +08:00
|
|
|
strm.Printf("command source -s %i '%s'\n",
|
|
|
|
static_cast<int>(source_quietly), command);
|
2016-09-07 04:57:50 +08:00
|
|
|
} else
|
2014-07-31 01:38:47 +08:00
|
|
|
strm.Printf("%s\n", command);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-06-23 09:19:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check the arguments that were passed to this program to make sure they are
|
2018-11-28 05:00:32 +08:00
|
|
|
// valid and to get their argument values (if any). Return a boolean value
|
|
|
|
// indicating whether or not to start up the full debugger (i.e. the Command
|
|
|
|
// Interpreter) or not. Return FALSE if the arguments were invalid OR if the
|
|
|
|
// user only wanted help or version information.
|
2018-11-29 06:39:17 +08:00
|
|
|
SBError Driver::ProcessArgs(const opt::InputArgList &args, bool &exiting) {
|
2018-11-28 05:00:32 +08:00
|
|
|
SBError error;
|
2010-06-23 09:19:29 +08:00
|
|
|
|
2018-11-28 05:00:32 +08:00
|
|
|
// This is kind of a pain, but since we make the debugger in the Driver's
|
|
|
|
// constructor, we can't know at that point whether we should read in init
|
|
|
|
// files yet. So we don't read them in in the Driver constructor, then set
|
|
|
|
// the flags back to "read them in" here, and then if we see the "-n" flag,
|
|
|
|
// we'll turn it off again. Finally we have to read them in by hand later in
|
|
|
|
// the main loop.
|
|
|
|
m_debugger.SkipLLDBInitFiles(false);
|
|
|
|
m_debugger.SkipAppInitFiles(false);
|
2018-09-29 01:58:16 +08:00
|
|
|
|
2022-03-01 05:59:19 +08:00
|
|
|
if (args.hasArg(OPT_no_use_colors)) {
|
|
|
|
m_debugger.SetUseColor(false);
|
|
|
|
WithColor::setAutoDetectFunction(disable_color);
|
|
|
|
m_option_data.m_debug_mode = true;
|
|
|
|
}
|
|
|
|
|
2018-11-28 05:00:32 +08:00
|
|
|
if (args.hasArg(OPT_version)) {
|
|
|
|
m_option_data.m_print_version = true;
|
|
|
|
}
|
2010-06-23 09:19:29 +08:00
|
|
|
|
2018-11-28 05:00:32 +08:00
|
|
|
if (args.hasArg(OPT_python_path)) {
|
|
|
|
m_option_data.m_print_python_path = true;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
[lldb] make it easier to find LLDB's python
It is surprisingly difficult to write a simple python script that
can reliably `import lldb` without failing, or crashing. I'm
currently resorting to convolutions like this:
def find_lldb(may_reexec=False):
if prefix := os.environ.get('LLDB_PYTHON_PREFIX'):
if os.path.realpath(prefix) != os.path.realpath(sys.prefix):
raise Exception("cannot import lldb.\n"
f" sys.prefix should be: {prefix}\n"
f" but it is: {sys.prefix}")
else:
line1, line2 = subprocess.run(
['lldb', '-x', '-b', '-o', 'script print(sys.prefix)'],
encoding='utf8', stdout=subprocess.PIPE,
check=True).stdout.strip().splitlines()
assert line1.strip() == '(lldb) script print(sys.prefix)'
prefix = line2.strip()
os.environ['LLDB_PYTHON_PREFIX'] = prefix
if sys.prefix != prefix:
if not may_reexec:
raise Exception(
"cannot import lldb.\n" +
f" This python, at {sys.prefix}\n"
f" does not math LLDB's python at {prefix}")
os.environ['LLDB_PYTHON_PREFIX'] = prefix
python_exe = os.path.join(prefix, 'bin', 'python3')
os.execl(python_exe, python_exe, *sys.argv)
lldb_path = subprocess.run(['lldb', '-P'],
check=True, stdout=subprocess.PIPE,
encoding='utf8').stdout.strip()
sys.path = [lldb_path] + sys.path
This patch aims to replace all that with:
#!/usr/bin/env lldb-python
import lldb
...
... by adding the following features:
* new command line option: --print-script-interpreter-info. This
prints language-specific information about the script interpreter
in JSON format.
* new tool (unix only): lldb-python which finds python and exec's it.
Reviewed By: JDevlieghere
Differential Revision: https://reviews.llvm.org/D112973
2021-11-11 02:33:33 +08:00
|
|
|
if (args.hasArg(OPT_print_script_interpreter_info)) {
|
|
|
|
m_option_data.m_print_script_interpreter_info = true;
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2018-11-28 05:00:32 +08:00
|
|
|
if (args.hasArg(OPT_batch)) {
|
|
|
|
m_option_data.m_batch = true;
|
|
|
|
}
|
|
|
|
|
2018-11-29 08:22:28 +08:00
|
|
|
if (auto *arg = args.getLastArg(OPT_core)) {
|
|
|
|
auto arg_value = arg->getValue();
|
|
|
|
SBFileSpec file(arg_value);
|
|
|
|
if (!file.Exists()) {
|
2018-11-28 05:00:32 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
2018-11-29 08:22:28 +08:00
|
|
|
"file specified in --core (-c) option doesn't exist: '%s'",
|
|
|
|
arg_value);
|
2018-11-28 05:00:32 +08:00
|
|
|
return error;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2018-11-29 08:22:28 +08:00
|
|
|
m_option_data.m_core_file = arg_value;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2018-11-28 05:00:32 +08:00
|
|
|
if (args.hasArg(OPT_editor)) {
|
|
|
|
m_option_data.m_use_external_editor = true;
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2018-11-28 05:00:32 +08:00
|
|
|
if (args.hasArg(OPT_no_lldbinit)) {
|
|
|
|
m_debugger.SkipLLDBInitFiles(true);
|
|
|
|
m_debugger.SkipAppInitFiles(true);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-05-08 00:57:17 +08:00
|
|
|
if (args.hasArg(OPT_local_lldbinit)) {
|
|
|
|
lldb::SBDebugger::SetInternalVariable("target.load-cwd-lldbinit", "true",
|
|
|
|
m_debugger.GetInstanceName());
|
|
|
|
}
|
|
|
|
|
2018-11-28 05:00:32 +08:00
|
|
|
if (auto *arg = args.getLastArg(OPT_file)) {
|
2018-11-29 08:22:28 +08:00
|
|
|
auto arg_value = arg->getValue();
|
|
|
|
SBFileSpec file(arg_value);
|
2018-11-28 05:00:32 +08:00
|
|
|
if (file.Exists()) {
|
2019-01-05 08:01:04 +08:00
|
|
|
m_option_data.m_args.emplace_back(arg_value);
|
2018-11-28 05:00:32 +08:00
|
|
|
} else if (file.ResolveExecutableLocation()) {
|
|
|
|
char path[PATH_MAX];
|
|
|
|
file.GetPath(path, sizeof(path));
|
2019-01-05 08:01:04 +08:00
|
|
|
m_option_data.m_args.emplace_back(path);
|
2018-11-28 05:00:32 +08:00
|
|
|
} else {
|
|
|
|
error.SetErrorStringWithFormat(
|
2018-11-29 08:22:28 +08:00
|
|
|
"file specified in --file (-f) option doesn't exist: '%s'",
|
|
|
|
arg_value);
|
2018-11-28 05:00:32 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto *arg = args.getLastArg(OPT_arch)) {
|
2018-11-29 08:22:28 +08:00
|
|
|
auto arg_value = arg->getValue();
|
2019-01-05 08:01:04 +08:00
|
|
|
if (!lldb::SBDebugger::SetDefaultArchitecture(arg_value)) {
|
2018-11-28 05:00:32 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
2018-11-29 08:22:28 +08:00
|
|
|
"invalid architecture in the -a or --arch option: '%s'", arg_value);
|
2018-11-28 05:00:32 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto *arg = args.getLastArg(OPT_script_language)) {
|
2018-11-29 08:22:28 +08:00
|
|
|
auto arg_value = arg->getValue();
|
2019-04-27 06:54:39 +08:00
|
|
|
m_debugger.SetScriptLanguage(m_debugger.GetScriptingLanguage(arg_value));
|
2018-11-28 05:00:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (args.hasArg(OPT_source_quietly)) {
|
|
|
|
m_option_data.m_source_quietly = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto *arg = args.getLastArg(OPT_attach_name)) {
|
2018-11-29 08:22:28 +08:00
|
|
|
auto arg_value = arg->getValue();
|
|
|
|
m_option_data.m_process_name = arg_value;
|
2018-11-28 05:00:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (args.hasArg(OPT_wait_for)) {
|
|
|
|
m_option_data.m_wait_for = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto *arg = args.getLastArg(OPT_attach_pid)) {
|
2018-11-29 08:22:28 +08:00
|
|
|
auto arg_value = arg->getValue();
|
2018-11-28 05:00:32 +08:00
|
|
|
char *remainder;
|
2018-11-29 08:22:28 +08:00
|
|
|
m_option_data.m_process_pid = strtol(arg_value, &remainder, 0);
|
|
|
|
if (remainder == arg_value || *remainder != '\0') {
|
2018-11-28 05:00:32 +08:00
|
|
|
error.SetErrorStringWithFormat(
|
2018-11-29 08:22:28 +08:00
|
|
|
"Could not convert process PID: \"%s\" into a pid.", arg_value);
|
2018-11-28 05:00:32 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto *arg = args.getLastArg(OPT_repl_language)) {
|
2018-11-29 08:22:28 +08:00
|
|
|
auto arg_value = arg->getValue();
|
2018-11-28 05:00:32 +08:00
|
|
|
m_option_data.m_repl_lang =
|
2018-11-29 08:22:28 +08:00
|
|
|
SBLanguageRuntime::GetLanguageTypeFromString(arg_value);
|
2018-11-28 05:00:32 +08:00
|
|
|
if (m_option_data.m_repl_lang == eLanguageTypeUnknown) {
|
|
|
|
error.SetErrorStringWithFormat("Unrecognized language name: \"%s\"",
|
2018-11-29 08:22:28 +08:00
|
|
|
arg_value);
|
2018-11-28 05:00:32 +08:00
|
|
|
return error;
|
|
|
|
}
|
2022-01-06 06:42:21 +08:00
|
|
|
m_debugger.SetREPLLanguage(m_option_data.m_repl_lang);
|
2018-11-28 05:00:32 +08:00
|
|
|
}
|
|
|
|
|
2018-12-18 02:11:48 +08:00
|
|
|
if (args.hasArg(OPT_repl)) {
|
|
|
|
m_option_data.m_repl = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto *arg = args.getLastArg(OPT_repl_)) {
|
2018-11-28 05:00:32 +08:00
|
|
|
m_option_data.m_repl = true;
|
2018-12-18 02:11:48 +08:00
|
|
|
if (auto arg_value = arg->getValue())
|
2018-11-29 08:22:28 +08:00
|
|
|
m_option_data.m_repl_options = arg_value;
|
2018-11-28 05:00:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// We need to process the options below together as their relative order
|
|
|
|
// matters.
|
|
|
|
for (auto *arg : args.filtered(OPT_source_on_crash, OPT_one_line_on_crash,
|
|
|
|
OPT_source, OPT_source_before_file,
|
|
|
|
OPT_one_line, OPT_one_line_before_file)) {
|
2018-11-29 08:22:28 +08:00
|
|
|
auto arg_value = arg->getValue();
|
2018-11-28 05:00:32 +08:00
|
|
|
if (arg->getOption().matches(OPT_source_on_crash)) {
|
2018-11-29 08:22:28 +08:00
|
|
|
m_option_data.AddInitialCommand(arg_value, eCommandPlacementAfterCrash,
|
|
|
|
true, error);
|
2018-11-28 05:00:32 +08:00
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg->getOption().matches(OPT_one_line_on_crash)) {
|
2018-11-29 08:22:28 +08:00
|
|
|
m_option_data.AddInitialCommand(arg_value, eCommandPlacementAfterCrash,
|
2018-11-28 05:00:32 +08:00
|
|
|
false, error);
|
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg->getOption().matches(OPT_source)) {
|
2018-11-29 08:22:28 +08:00
|
|
|
m_option_data.AddInitialCommand(arg_value, eCommandPlacementAfterFile,
|
|
|
|
true, error);
|
2018-11-28 05:00:32 +08:00
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg->getOption().matches(OPT_source_before_file)) {
|
2018-11-29 08:22:28 +08:00
|
|
|
m_option_data.AddInitialCommand(arg_value, eCommandPlacementBeforeFile,
|
|
|
|
true, error);
|
2018-11-28 05:00:32 +08:00
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg->getOption().matches(OPT_one_line)) {
|
2018-11-29 08:22:28 +08:00
|
|
|
m_option_data.AddInitialCommand(arg_value, eCommandPlacementAfterFile,
|
|
|
|
false, error);
|
2018-11-28 05:00:32 +08:00
|
|
|
if (error.Fail())
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (arg->getOption().matches(OPT_one_line_before_file)) {
|
2018-11-29 08:22:28 +08:00
|
|
|
m_option_data.AddInitialCommand(arg_value, eCommandPlacementBeforeFile,
|
2018-11-28 05:00:32 +08:00
|
|
|
false, error);
|
|
|
|
if (error.Fail())
|
2013-10-15 23:46:40 +08:00
|
|
|
return error;
|
2018-11-28 05:00:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_option_data.m_process_name.empty() &&
|
|
|
|
m_option_data.m_process_pid == LLDB_INVALID_PROCESS_ID) {
|
|
|
|
|
2020-05-19 09:10:53 +08:00
|
|
|
for (auto *arg : args.filtered(OPT_INPUT))
|
|
|
|
m_option_data.m_args.push_back(arg->getAsString((args)));
|
2018-11-28 05:00:32 +08:00
|
|
|
|
|
|
|
// Any argument following -- is an argument for the inferior.
|
|
|
|
if (auto *arg = args.getLastArgNoClaim(OPT_REM)) {
|
|
|
|
for (auto value : arg->getValues())
|
2019-01-05 08:01:04 +08:00
|
|
|
m_option_data.m_args.emplace_back(value);
|
2018-11-28 05:00:32 +08:00
|
|
|
}
|
2019-01-05 08:01:04 +08:00
|
|
|
} else if (args.getLastArgNoClaim() != nullptr) {
|
2018-11-29 06:39:17 +08:00
|
|
|
WithColor::warning() << "program arguments are ignored when attaching.\n";
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2018-11-28 05:00:32 +08:00
|
|
|
if (m_option_data.m_print_version) {
|
2019-01-05 08:01:04 +08:00
|
|
|
llvm::outs() << lldb::SBDebugger::GetVersionString() << '\n';
|
2013-10-15 23:46:40 +08:00
|
|
|
exiting = true;
|
2018-11-28 05:00:32 +08:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_option_data.m_print_python_path) {
|
2011-09-14 07:25:31 +08:00
|
|
|
SBFileSpec python_file_spec = SBHostOS::GetLLDBPythonPath();
|
|
|
|
if (python_file_spec.IsValid()) {
|
2010-12-09 06:23:24 +08:00
|
|
|
char python_path[PATH_MAX];
|
|
|
|
size_t num_chars = python_file_spec.GetPath(python_path, PATH_MAX);
|
|
|
|
if (num_chars < PATH_MAX) {
|
2018-11-29 06:39:17 +08:00
|
|
|
llvm::outs() << python_path << '\n';
|
2010-12-09 06:23:24 +08:00
|
|
|
} else
|
2018-11-29 06:39:17 +08:00
|
|
|
llvm::outs() << "<PATH TOO LONG>\n";
|
2016-09-07 04:57:50 +08:00
|
|
|
} else
|
2018-11-29 06:39:17 +08:00
|
|
|
llvm::outs() << "<COULD NOT FIND PATH>\n";
|
2010-12-09 06:23:24 +08:00
|
|
|
exiting = true;
|
2018-11-28 05:00:32 +08:00
|
|
|
return error;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
[lldb] make it easier to find LLDB's python
It is surprisingly difficult to write a simple python script that
can reliably `import lldb` without failing, or crashing. I'm
currently resorting to convolutions like this:
def find_lldb(may_reexec=False):
if prefix := os.environ.get('LLDB_PYTHON_PREFIX'):
if os.path.realpath(prefix) != os.path.realpath(sys.prefix):
raise Exception("cannot import lldb.\n"
f" sys.prefix should be: {prefix}\n"
f" but it is: {sys.prefix}")
else:
line1, line2 = subprocess.run(
['lldb', '-x', '-b', '-o', 'script print(sys.prefix)'],
encoding='utf8', stdout=subprocess.PIPE,
check=True).stdout.strip().splitlines()
assert line1.strip() == '(lldb) script print(sys.prefix)'
prefix = line2.strip()
os.environ['LLDB_PYTHON_PREFIX'] = prefix
if sys.prefix != prefix:
if not may_reexec:
raise Exception(
"cannot import lldb.\n" +
f" This python, at {sys.prefix}\n"
f" does not math LLDB's python at {prefix}")
os.environ['LLDB_PYTHON_PREFIX'] = prefix
python_exe = os.path.join(prefix, 'bin', 'python3')
os.execl(python_exe, python_exe, *sys.argv)
lldb_path = subprocess.run(['lldb', '-P'],
check=True, stdout=subprocess.PIPE,
encoding='utf8').stdout.strip()
sys.path = [lldb_path] + sys.path
This patch aims to replace all that with:
#!/usr/bin/env lldb-python
import lldb
...
... by adding the following features:
* new command line option: --print-script-interpreter-info. This
prints language-specific information about the script interpreter
in JSON format.
* new tool (unix only): lldb-python which finds python and exec's it.
Reviewed By: JDevlieghere
Differential Revision: https://reviews.llvm.org/D112973
2021-11-11 02:33:33 +08:00
|
|
|
if (m_option_data.m_print_script_interpreter_info) {
|
|
|
|
SBStructuredData info =
|
|
|
|
m_debugger.GetScriptInterpreterInfo(m_debugger.GetScriptLanguage());
|
|
|
|
if (!info) {
|
|
|
|
error.SetErrorString("no script interpreter.");
|
|
|
|
} else {
|
|
|
|
SBStream stream;
|
|
|
|
error = info.GetAsJSON(stream);
|
|
|
|
if (error.Success()) {
|
|
|
|
llvm::outs() << stream.GetData() << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exiting = true;
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
return error;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2015-03-06 03:17:56 +08:00
|
|
|
std::string EscapeString(std::string arg) {
|
|
|
|
std::string::size_type pos = 0;
|
|
|
|
while ((pos = arg.find_first_of("\"\\", pos)) != std::string::npos) {
|
|
|
|
arg.insert(pos, 1, '\\');
|
|
|
|
pos += 2;
|
|
|
|
}
|
|
|
|
return '"' + arg + '"';
|
|
|
|
}
|
|
|
|
|
2018-07-12 01:18:01 +08:00
|
|
|
int Driver::MainLoop() {
|
2010-06-09 00:52:24 +08:00
|
|
|
if (::tcgetattr(STDIN_FILENO, &g_old_stdin_termios) == 0) {
|
2012-02-03 03:28:31 +08:00
|
|
|
g_old_stdin_termios_is_valid = true;
|
2010-06-09 00:52:24 +08:00
|
|
|
atexit(reset_stdin_termios);
|
2012-02-03 03:28:31 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-04-15 07:31:17 +08:00
|
|
|
#ifndef _MSC_VER
|
|
|
|
// Disabling stdin buffering with MSVC's 2015 CRT exposes a bug in fgets
|
|
|
|
// which causes it to miss newlines depending on whether there have been an
|
|
|
|
// odd or even number of characters. Bug has been reported to MS via Connect.
|
2019-01-05 08:01:04 +08:00
|
|
|
::setbuf(stdin, nullptr);
|
2016-04-15 07:31:17 +08:00
|
|
|
#endif
|
2019-01-05 08:01:04 +08:00
|
|
|
::setbuf(stdout, nullptr);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-23 09:19:29 +08:00
|
|
|
m_debugger.SetErrorFileHandle(stderr, false);
|
|
|
|
m_debugger.SetOutputFileHandle(stdout, false);
|
2019-04-27 06:54:39 +08:00
|
|
|
// Don't take ownership of STDIN yet...
|
|
|
|
m_debugger.SetInputFileHandle(stdin, false);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-08-31 03:44:40 +08:00
|
|
|
m_debugger.SetUseExternalEditor(m_option_data.m_use_external_editor);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2010-06-09 00:52:24 +08:00
|
|
|
struct winsize window_size;
|
2019-01-05 08:01:04 +08:00
|
|
|
if ((isatty(STDIN_FILENO) != 0) &&
|
2010-06-09 00:52:24 +08:00
|
|
|
::ioctl(STDIN_FILENO, TIOCGWINSZ, &window_size) == 0) {
|
2010-09-04 08:03:46 +08:00
|
|
|
if (window_size.ws_col > 0)
|
2010-09-18 09:14:36 +08:00
|
|
|
m_debugger.SetTerminalWidth(window_size.ws_col);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
SBCommandInterpreter sb_interpreter = m_debugger.GetCommandInterpreter();
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2022-02-15 20:28:34 +08:00
|
|
|
// Process lldbinit files before handling any options from the command line.
|
2014-01-28 07:43:24 +08:00
|
|
|
SBCommandReturnObject result;
|
2022-02-15 20:28:34 +08:00
|
|
|
sb_interpreter.SourceInitFileInGlobalDirectory(result);
|
|
|
|
if (m_option_data.m_debug_mode) {
|
|
|
|
result.PutError(m_debugger.GetErrorFile());
|
|
|
|
result.PutOutput(m_debugger.GetOutputFile());
|
|
|
|
}
|
|
|
|
|
2020-08-20 04:04:35 +08:00
|
|
|
sb_interpreter.SourceInitFileInHomeDirectory(result, m_option_data.m_repl);
|
2019-04-27 06:54:39 +08:00
|
|
|
if (m_option_data.m_debug_mode) {
|
2019-10-10 05:50:49 +08:00
|
|
|
result.PutError(m_debugger.GetErrorFile());
|
|
|
|
result.PutOutput(m_debugger.GetOutputFile());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2019-05-07 04:45:31 +08:00
|
|
|
// Source the local .lldbinit file if it exists and we're allowed to source.
|
|
|
|
// Here we want to always print the return object because it contains the
|
|
|
|
// warning and instructions to load local lldbinit files.
|
|
|
|
sb_interpreter.SourceInitFileInCurrentWorkingDirectory(result);
|
2019-10-10 05:50:49 +08:00
|
|
|
result.PutError(m_debugger.GetErrorFile());
|
|
|
|
result.PutOutput(m_debugger.GetOutputFile());
|
2019-05-07 04:45:31 +08:00
|
|
|
|
2018-07-12 01:18:01 +08:00
|
|
|
// We allow the user to specify an exit code when calling quit which we will
|
|
|
|
// return when exiting.
|
|
|
|
m_debugger.GetCommandInterpreter().AllowExitCodeOnQuit(true);
|
|
|
|
|
2014-01-28 07:43:24 +08:00
|
|
|
// Now we handle options we got from the command line
|
2014-07-31 03:26:11 +08:00
|
|
|
SBStream commands_stream;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2014-07-31 01:38:47 +08:00
|
|
|
// First source in the commands specified to be run before the file arguments
|
|
|
|
// are processed.
|
2016-02-19 08:05:17 +08:00
|
|
|
WriteCommandsForSourcing(eCommandPlacementBeforeFile, commands_stream);
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-03-25 23:38:18 +08:00
|
|
|
// If we're not in --repl mode, add the commands to process the file
|
|
|
|
// arguments, and the commands specified to run afterwards.
|
|
|
|
if (!m_option_data.m_repl) {
|
|
|
|
const size_t num_args = m_option_data.m_args.size();
|
|
|
|
if (num_args > 0) {
|
|
|
|
char arch_name[64];
|
2019-04-27 06:54:39 +08:00
|
|
|
if (lldb::SBDebugger::GetDefaultArchitecture(arch_name,
|
|
|
|
sizeof(arch_name)))
|
2019-03-25 23:38:18 +08:00
|
|
|
commands_stream.Printf("target create --arch=%s %s", arch_name,
|
|
|
|
EscapeString(m_option_data.m_args[0]).c_str());
|
|
|
|
else
|
|
|
|
commands_stream.Printf("target create %s",
|
|
|
|
EscapeString(m_option_data.m_args[0]).c_str());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-03-25 23:38:18 +08:00
|
|
|
if (!m_option_data.m_core_file.empty()) {
|
|
|
|
commands_stream.Printf(" --core %s",
|
|
|
|
EscapeString(m_option_data.m_core_file).c_str());
|
|
|
|
}
|
2014-01-28 07:43:24 +08:00
|
|
|
commands_stream.Printf("\n");
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-03-25 23:38:18 +08:00
|
|
|
if (num_args > 1) {
|
|
|
|
commands_stream.Printf("settings set -- target.run-args ");
|
|
|
|
for (size_t arg_idx = 1; arg_idx < num_args; ++arg_idx)
|
|
|
|
commands_stream.Printf(
|
|
|
|
" %s", EscapeString(m_option_data.m_args[arg_idx]).c_str());
|
|
|
|
commands_stream.Printf("\n");
|
|
|
|
}
|
|
|
|
} else if (!m_option_data.m_core_file.empty()) {
|
|
|
|
commands_stream.Printf("target create --core %s\n",
|
|
|
|
EscapeString(m_option_data.m_core_file).c_str());
|
|
|
|
} else if (!m_option_data.m_process_name.empty()) {
|
2019-04-27 06:54:39 +08:00
|
|
|
commands_stream.Printf(
|
|
|
|
"process attach --name %s",
|
|
|
|
EscapeString(m_option_data.m_process_name).c_str());
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-03-25 23:38:18 +08:00
|
|
|
if (m_option_data.m_wait_for)
|
|
|
|
commands_stream.Printf(" --waitfor");
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-03-25 23:38:18 +08:00
|
|
|
commands_stream.Printf("\n");
|
|
|
|
|
|
|
|
} else if (LLDB_INVALID_PROCESS_ID != m_option_data.m_process_pid) {
|
|
|
|
commands_stream.Printf("process attach --pid %" PRIu64 "\n",
|
|
|
|
m_option_data.m_process_pid);
|
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-03-25 23:38:18 +08:00
|
|
|
WriteCommandsForSourcing(eCommandPlacementAfterFile, commands_stream);
|
|
|
|
} else if (!m_option_data.m_after_file_commands.empty()) {
|
|
|
|
// We're in repl mode and after-file-load commands were specified.
|
|
|
|
WithColor::warning() << "commands specified to run after file load (via -o "
|
2019-04-27 06:54:39 +08:00
|
|
|
"or -s) are ignored in REPL mode.\n";
|
2019-03-25 23:38:18 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-04-27 06:54:39 +08:00
|
|
|
if (m_option_data.m_debug_mode) {
|
2019-10-10 05:50:49 +08:00
|
|
|
result.PutError(m_debugger.GetErrorFile());
|
|
|
|
result.PutOutput(m_debugger.GetOutputFile());
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
|
2019-04-27 06:54:39 +08:00
|
|
|
const bool handle_events = true;
|
|
|
|
const bool spawn_thread = false;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2019-03-25 23:38:18 +08:00
|
|
|
// Check if we have any data in the commands stream, and if so, save it to a
|
|
|
|
// temp file
|
|
|
|
// so we can then run the command interpreter using the file contents.
|
2020-05-02 04:23:51 +08:00
|
|
|
bool go_interactive = true;
|
2021-11-25 00:13:48 +08:00
|
|
|
if ((commands_stream.GetData() != nullptr) &&
|
|
|
|
(commands_stream.GetSize() != 0u)) {
|
|
|
|
SBError error = m_debugger.SetInputString(commands_stream.GetData());
|
|
|
|
if (error.Fail()) {
|
|
|
|
WithColor::error() << error.GetCString() << '\n';
|
2020-11-10 08:36:47 +08:00
|
|
|
return 1;
|
2019-03-25 23:38:18 +08:00
|
|
|
}
|
2020-04-25 03:50:06 +08:00
|
|
|
|
2020-05-02 04:23:51 +08:00
|
|
|
// Set the debugger into Sync mode when running the command file. Otherwise
|
|
|
|
// command files that run the target won't run in a sensible way.
|
2020-04-25 03:50:06 +08:00
|
|
|
bool old_async = m_debugger.GetAsync();
|
|
|
|
m_debugger.SetAsync(false);
|
|
|
|
|
|
|
|
SBCommandInterpreterRunOptions options;
|
2020-05-02 04:23:51 +08:00
|
|
|
options.SetAutoHandleEvents(true);
|
|
|
|
options.SetSpawnThread(false);
|
2020-04-25 03:50:06 +08:00
|
|
|
options.SetStopOnError(true);
|
2020-05-02 04:23:51 +08:00
|
|
|
options.SetStopOnCrash(m_option_data.m_batch);
|
2021-11-03 02:01:53 +08:00
|
|
|
options.SetEchoCommands(!m_option_data.m_source_quietly);
|
2020-05-02 04:23:51 +08:00
|
|
|
|
|
|
|
SBCommandInterpreterRunResult results =
|
|
|
|
m_debugger.RunCommandInterpreter(options);
|
|
|
|
if (results.GetResult() == lldb::eCommandInterpreterResultQuitRequested)
|
|
|
|
go_interactive = false;
|
|
|
|
if (m_option_data.m_batch &&
|
|
|
|
results.GetResult() != lldb::eCommandInterpreterResultInferiorCrash)
|
|
|
|
go_interactive = false;
|
|
|
|
|
2020-05-06 01:58:03 +08:00
|
|
|
// When running in batch mode and stopped because of an error, exit with a
|
|
|
|
// non-zero exit status.
|
|
|
|
if (m_option_data.m_batch &&
|
|
|
|
results.GetResult() == lldb::eCommandInterpreterResultCommandError)
|
2020-11-10 08:36:47 +08:00
|
|
|
return 1;
|
2020-05-06 01:58:03 +08:00
|
|
|
|
2020-05-02 04:23:51 +08:00
|
|
|
if (m_option_data.m_batch &&
|
|
|
|
results.GetResult() == lldb::eCommandInterpreterResultInferiorCrash &&
|
2020-04-25 03:50:06 +08:00
|
|
|
!m_option_data.m_after_crash_commands.empty()) {
|
|
|
|
SBStream crash_commands_stream;
|
|
|
|
WriteCommandsForSourcing(eCommandPlacementAfterCrash,
|
|
|
|
crash_commands_stream);
|
2021-11-25 00:13:48 +08:00
|
|
|
SBError error =
|
|
|
|
m_debugger.SetInputString(crash_commands_stream.GetData());
|
|
|
|
if (error.Success()) {
|
2020-05-02 04:23:51 +08:00
|
|
|
SBCommandInterpreterRunResult local_results =
|
|
|
|
m_debugger.RunCommandInterpreter(options);
|
|
|
|
if (local_results.GetResult() ==
|
|
|
|
lldb::eCommandInterpreterResultQuitRequested)
|
|
|
|
go_interactive = false;
|
2020-05-06 01:58:03 +08:00
|
|
|
|
|
|
|
// When running in batch mode and an error occurred while sourcing
|
|
|
|
// the crash commands, exit with a non-zero exit status.
|
|
|
|
if (m_option_data.m_batch &&
|
|
|
|
local_results.GetResult() ==
|
|
|
|
lldb::eCommandInterpreterResultCommandError)
|
2020-11-10 08:36:47 +08:00
|
|
|
return 1;
|
2020-04-25 03:50:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
m_debugger.SetAsync(old_async);
|
2019-03-25 23:38:18 +08:00
|
|
|
}
|
2014-07-31 01:38:47 +08:00
|
|
|
|
2020-05-02 04:23:51 +08:00
|
|
|
// Now set the input file handle to STDIN and run the command interpreter
|
|
|
|
// again in interactive mode or repl mode and let the debugger take ownership
|
|
|
|
// of stdin.
|
2019-03-25 23:38:18 +08:00
|
|
|
if (go_interactive) {
|
|
|
|
m_debugger.SetInputFileHandle(stdin, true);
|
|
|
|
|
|
|
|
if (m_option_data.m_repl) {
|
|
|
|
const char *repl_options = nullptr;
|
|
|
|
if (!m_option_data.m_repl_options.empty())
|
|
|
|
repl_options = m_option_data.m_repl_options.c_str();
|
2019-04-27 06:54:39 +08:00
|
|
|
SBError error(
|
|
|
|
m_debugger.RunREPL(m_option_data.m_repl_lang, repl_options));
|
2019-03-25 23:38:18 +08:00
|
|
|
if (error.Fail()) {
|
|
|
|
const char *error_cstr = error.GetCString();
|
|
|
|
if ((error_cstr != nullptr) && (error_cstr[0] != 0))
|
|
|
|
WithColor::error() << error_cstr << '\n';
|
|
|
|
else
|
|
|
|
WithColor::error() << error.GetError() << '\n';
|
|
|
|
}
|
|
|
|
} else {
|
2015-10-20 08:23:46 +08:00
|
|
|
m_debugger.RunCommandInterpreter(handle_events, spawn_thread);
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
|
|
|
}
|
2014-10-11 08:38:27 +08:00
|
|
|
|
2015-10-20 08:23:46 +08:00
|
|
|
reset_stdin_termios();
|
|
|
|
fclose(stdin);
|
2014-10-14 09:20:07 +08:00
|
|
|
|
2020-11-10 08:36:03 +08:00
|
|
|
return sb_interpreter.GetQuitStatus();
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|
|
|
|
|
2013-02-23 06:56:55 +08:00
|
|
|
void Driver::ResizeWindow(unsigned short col) {
|
|
|
|
GetDebugger().SetTerminalWidth(col);
|
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2010-09-10 01:45:09 +08:00
|
|
|
void sigwinch_handler(int signo) {
|
|
|
|
struct winsize window_size;
|
2019-01-05 08:01:04 +08:00
|
|
|
if ((isatty(STDIN_FILENO) != 0) &&
|
2010-09-10 01:45:09 +08:00
|
|
|
::ioctl(STDIN_FILENO, TIOCGWINSZ, &window_size) == 0) {
|
2019-01-05 08:01:04 +08:00
|
|
|
if ((window_size.ws_col > 0) && g_driver != nullptr) {
|
2013-02-23 06:56:55 +08:00
|
|
|
g_driver->ResizeWindow(window_size.ws_col);
|
2010-09-10 01:45:09 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-09-10 01:45:09 +08:00
|
|
|
}
|
|
|
|
|
2010-11-20 04:47:54 +08:00
|
|
|
void sigint_handler(int signo) {
|
2019-07-12 12:43:46 +08:00
|
|
|
#ifdef _WIN32 // Restore handler as it is not persistent on Windows
|
|
|
|
signal(SIGINT, sigint_handler);
|
|
|
|
#endif
|
2017-09-21 02:09:39 +08:00
|
|
|
static std::atomic_flag g_interrupt_sent = ATOMIC_FLAG_INIT;
|
2019-01-05 08:01:04 +08:00
|
|
|
if (g_driver != nullptr) {
|
2017-09-21 02:09:39 +08:00
|
|
|
if (!g_interrupt_sent.test_and_set()) {
|
2010-11-20 04:47:54 +08:00
|
|
|
g_driver->GetDebugger().DispatchInputInterrupt();
|
2017-09-21 02:09:39 +08:00
|
|
|
g_interrupt_sent.clear();
|
2010-11-20 04:47:54 +08:00
|
|
|
return;
|
2016-09-07 04:57:50 +08:00
|
|
|
}
|
2010-11-20 04:47:54 +08:00
|
|
|
}
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2017-09-21 02:09:39 +08:00
|
|
|
_exit(signo);
|
2010-11-20 04:47:54 +08:00
|
|
|
}
|
|
|
|
|
[lldb/driver] Fix SIGTSTP handling
Our SIGTSTP handler was working, but that was mostly accidental.
The reason it worked is because lldb is multithreaded for most of its
lifetime and the OS is reasonably fast at responding to signals. So,
what happened was that the kill(SIGTSTP) which we sent from inside the
handler was delivered to another thread while the handler was still set
to SIG_DFL (which then correctly put the entire process to sleep).
Sometimes it happened that the other thread got the second signal after
the first thread had already restored the handler, in which case the
signal handler would run again, and it would again attempt to send the
SIGTSTP signal back to itself.
Normally it didn't take many iterations for the signal to be delivered
quickly enough. However, if you were unlucky (or were playing around
with pexpect) you could get SIGTSTP while lldb was single-threaded, and
in that case, lldb would go into an endless loop because the second
SIGTSTP could only be handled on the main thread, and only after the
handler for the first signal returned (and re-installed itself). In that
situation the handler would keep re-sending the signal to itself.
This patch fixes the issue by implementing the handler the way it
supposed to be done:
- before sending the second SIGTSTP, we unblock the signal (it gets
automatically blocked upon entering the handler)
- we use raise to send the signal, which makes sure it gets delivered to
the thread which is running the handler
This also means we don't need the SIGCONT handler, as our TSTP handler
resumes right after the entire process is continued, and we can do the
required work there.
I also include a test case for the SIGTSTP flow. It uses pexpect, but it
includes a couple of extra twists. Specifically, I needed to create an
extra process on top of lldb, which will run lldb in a separate process
group and simulate the role of the shell. This is needed because SIGTSTP
is not effective on a session leader (the signal gets delivered, but it
does not cause a stop) -- normally there isn't anyone to notice the
stop.
Differential Revision: https://reviews.llvm.org/D120320
2022-02-22 21:25:39 +08:00
|
|
|
#ifndef _WIN32
|
|
|
|
static void sigtstp_handler(int signo) {
|
2019-01-05 08:01:04 +08:00
|
|
|
if (g_driver != nullptr)
|
2016-04-12 00:40:09 +08:00
|
|
|
g_driver->GetDebugger().SaveInputTerminalState();
|
|
|
|
|
[lldb/driver] Fix SIGTSTP handling
Our SIGTSTP handler was working, but that was mostly accidental.
The reason it worked is because lldb is multithreaded for most of its
lifetime and the OS is reasonably fast at responding to signals. So,
what happened was that the kill(SIGTSTP) which we sent from inside the
handler was delivered to another thread while the handler was still set
to SIG_DFL (which then correctly put the entire process to sleep).
Sometimes it happened that the other thread got the second signal after
the first thread had already restored the handler, in which case the
signal handler would run again, and it would again attempt to send the
SIGTSTP signal back to itself.
Normally it didn't take many iterations for the signal to be delivered
quickly enough. However, if you were unlucky (or were playing around
with pexpect) you could get SIGTSTP while lldb was single-threaded, and
in that case, lldb would go into an endless loop because the second
SIGTSTP could only be handled on the main thread, and only after the
handler for the first signal returned (and re-installed itself). In that
situation the handler would keep re-sending the signal to itself.
This patch fixes the issue by implementing the handler the way it
supposed to be done:
- before sending the second SIGTSTP, we unblock the signal (it gets
automatically blocked upon entering the handler)
- we use raise to send the signal, which makes sure it gets delivered to
the thread which is running the handler
This also means we don't need the SIGCONT handler, as our TSTP handler
resumes right after the entire process is continued, and we can do the
required work there.
I also include a test case for the SIGTSTP flow. It uses pexpect, but it
includes a couple of extra twists. Specifically, I needed to create an
extra process on top of lldb, which will run lldb in a separate process
group and simulate the role of the shell. This is needed because SIGTSTP
is not effective on a session leader (the signal gets delivered, but it
does not cause a stop) -- normally there isn't anyone to notice the
stop.
Differential Revision: https://reviews.llvm.org/D120320
2022-02-22 21:25:39 +08:00
|
|
|
// Unblock the signal and remove our handler.
|
|
|
|
sigset_t set;
|
|
|
|
sigemptyset(&set);
|
|
|
|
sigaddset(&set, signo);
|
|
|
|
pthread_sigmask(SIG_UNBLOCK, &set, nullptr);
|
2012-12-01 04:23:19 +08:00
|
|
|
signal(signo, SIG_DFL);
|
[lldb/driver] Fix SIGTSTP handling
Our SIGTSTP handler was working, but that was mostly accidental.
The reason it worked is because lldb is multithreaded for most of its
lifetime and the OS is reasonably fast at responding to signals. So,
what happened was that the kill(SIGTSTP) which we sent from inside the
handler was delivered to another thread while the handler was still set
to SIG_DFL (which then correctly put the entire process to sleep).
Sometimes it happened that the other thread got the second signal after
the first thread had already restored the handler, in which case the
signal handler would run again, and it would again attempt to send the
SIGTSTP signal back to itself.
Normally it didn't take many iterations for the signal to be delivered
quickly enough. However, if you were unlucky (or were playing around
with pexpect) you could get SIGTSTP while lldb was single-threaded, and
in that case, lldb would go into an endless loop because the second
SIGTSTP could only be handled on the main thread, and only after the
handler for the first signal returned (and re-installed itself). In that
situation the handler would keep re-sending the signal to itself.
This patch fixes the issue by implementing the handler the way it
supposed to be done:
- before sending the second SIGTSTP, we unblock the signal (it gets
automatically blocked upon entering the handler)
- we use raise to send the signal, which makes sure it gets delivered to
the thread which is running the handler
This also means we don't need the SIGCONT handler, as our TSTP handler
resumes right after the entire process is continued, and we can do the
required work there.
I also include a test case for the SIGTSTP flow. It uses pexpect, but it
includes a couple of extra twists. Specifically, I needed to create an
extra process on top of lldb, which will run lldb in a separate process
group and simulate the role of the shell. This is needed because SIGTSTP
is not effective on a session leader (the signal gets delivered, but it
does not cause a stop) -- normally there isn't anyone to notice the
stop.
Differential Revision: https://reviews.llvm.org/D120320
2022-02-22 21:25:39 +08:00
|
|
|
|
|
|
|
// Now re-raise the signal. We will immediately suspend...
|
|
|
|
raise(signo);
|
|
|
|
// ... and resume after a SIGCONT.
|
|
|
|
|
|
|
|
// Now undo the modifications.
|
|
|
|
pthread_sigmask(SIG_BLOCK, &set, nullptr);
|
2012-12-01 04:23:19 +08:00
|
|
|
signal(signo, sigtstp_handler);
|
|
|
|
|
2019-01-05 08:01:04 +08:00
|
|
|
if (g_driver != nullptr)
|
2016-04-12 00:40:09 +08:00
|
|
|
g_driver->GetDebugger().RestoreInputTerminalState();
|
2012-12-01 04:23:19 +08:00
|
|
|
}
|
[lldb/driver] Fix SIGTSTP handling
Our SIGTSTP handler was working, but that was mostly accidental.
The reason it worked is because lldb is multithreaded for most of its
lifetime and the OS is reasonably fast at responding to signals. So,
what happened was that the kill(SIGTSTP) which we sent from inside the
handler was delivered to another thread while the handler was still set
to SIG_DFL (which then correctly put the entire process to sleep).
Sometimes it happened that the other thread got the second signal after
the first thread had already restored the handler, in which case the
signal handler would run again, and it would again attempt to send the
SIGTSTP signal back to itself.
Normally it didn't take many iterations for the signal to be delivered
quickly enough. However, if you were unlucky (or were playing around
with pexpect) you could get SIGTSTP while lldb was single-threaded, and
in that case, lldb would go into an endless loop because the second
SIGTSTP could only be handled on the main thread, and only after the
handler for the first signal returned (and re-installed itself). In that
situation the handler would keep re-sending the signal to itself.
This patch fixes the issue by implementing the handler the way it
supposed to be done:
- before sending the second SIGTSTP, we unblock the signal (it gets
automatically blocked upon entering the handler)
- we use raise to send the signal, which makes sure it gets delivered to
the thread which is running the handler
This also means we don't need the SIGCONT handler, as our TSTP handler
resumes right after the entire process is continued, and we can do the
required work there.
I also include a test case for the SIGTSTP flow. It uses pexpect, but it
includes a couple of extra twists. Specifically, I needed to create an
extra process on top of lldb, which will run lldb in a separate process
group and simulate the role of the shell. This is needed because SIGTSTP
is not effective on a session leader (the signal gets delivered, but it
does not cause a stop) -- normally there isn't anyone to notice the
stop.
Differential Revision: https://reviews.llvm.org/D120320
2022-02-22 21:25:39 +08:00
|
|
|
#endif
|
2012-12-01 04:23:19 +08:00
|
|
|
|
2018-11-28 05:00:32 +08:00
|
|
|
static void printHelp(LLDBOptTable &table, llvm::StringRef tool_name) {
|
2019-11-21 05:48:58 +08:00
|
|
|
std::string usage_str = tool_name.str() + " [options]";
|
2021-06-25 05:47:03 +08:00
|
|
|
table.printHelp(llvm::outs(), usage_str.c_str(), "LLDB", false);
|
2018-11-28 05:00:32 +08:00
|
|
|
|
|
|
|
std::string examples = R"___(
|
|
|
|
EXAMPLES:
|
|
|
|
The debugger can be started in several modes.
|
|
|
|
|
|
|
|
Passing an executable as a positional argument prepares lldb to debug the
|
2020-05-19 09:10:53 +08:00
|
|
|
given executable. To disambiguate between arguments passed to lldb and
|
|
|
|
arguments passed to the debugged executable, arguments starting with a - must
|
|
|
|
be passed after --.
|
|
|
|
|
2021-05-05 12:55:36 +08:00
|
|
|
lldb --arch x86_64 /path/to/program program argument -- --arch armv7
|
2020-05-19 09:10:53 +08:00
|
|
|
|
|
|
|
For convenience, passing the executable after -- is also supported.
|
2018-11-28 05:00:32 +08:00
|
|
|
|
2021-05-05 12:55:36 +08:00
|
|
|
lldb --arch x86_64 -- /path/to/program program argument --arch armv7
|
2018-11-28 05:00:32 +08:00
|
|
|
|
|
|
|
Passing one of the attach options causes lldb to immediately attach to the
|
|
|
|
given process.
|
|
|
|
|
|
|
|
lldb -p <pid>
|
|
|
|
lldb -n <process-name>
|
|
|
|
|
|
|
|
Passing --repl starts lldb in REPL mode.
|
|
|
|
|
|
|
|
lldb -r
|
|
|
|
|
|
|
|
Passing --core causes lldb to debug the core file.
|
|
|
|
|
|
|
|
lldb -c /path/to/core
|
|
|
|
|
2019-03-25 23:38:18 +08:00
|
|
|
Command options can be combined with these modes and cause lldb to run the
|
2018-11-28 05:00:32 +08:00
|
|
|
specified commands before or after events, like loading the file or crashing,
|
|
|
|
in the order provided on the command line.
|
|
|
|
|
|
|
|
lldb -O 'settings set stop-disassembly-count 20' -o 'run' -o 'bt'
|
|
|
|
lldb -S /source/before/file -s /source/after/file
|
|
|
|
lldb -K /source/before/crash -k /source/after/crash
|
2019-03-25 23:38:18 +08:00
|
|
|
|
|
|
|
Note: In REPL mode no file is loaded, so commands specified to run after
|
2019-11-22 05:36:36 +08:00
|
|
|
loading the file (via -o or -s) will be ignored.)___";
|
|
|
|
llvm::outs() << examples << '\n';
|
2018-11-28 05:00:32 +08:00
|
|
|
}
|
|
|
|
|
2021-04-20 10:39:10 +08:00
|
|
|
static llvm::Optional<int> InitializeReproducer(llvm::StringRef argv0,
|
|
|
|
opt::InputArgList &input_args) {
|
2019-03-13 00:44:18 +08:00
|
|
|
bool capture = input_args.hasArg(OPT_capture);
|
2020-07-10 01:35:16 +08:00
|
|
|
bool generate_on_exit = input_args.hasArg(OPT_generate_on_exit);
|
2019-03-13 00:44:18 +08:00
|
|
|
auto *capture_path = input_args.getLastArg(OPT_capture_path);
|
|
|
|
|
2020-07-10 01:35:16 +08:00
|
|
|
if (generate_on_exit && !capture) {
|
2020-01-16 11:44:46 +08:00
|
|
|
WithColor::warning()
|
2020-07-10 01:35:16 +08:00
|
|
|
<< "-reproducer-generate-on-exit specified without -capture\n";
|
2020-01-16 11:44:46 +08:00
|
|
|
}
|
|
|
|
|
2019-03-13 00:44:18 +08:00
|
|
|
if (capture || capture_path) {
|
|
|
|
if (capture_path) {
|
|
|
|
if (!capture)
|
|
|
|
WithColor::warning() << "-capture-path specified without -capture\n";
|
|
|
|
if (const char *error = SBReproducer::Capture(capture_path->getValue())) {
|
|
|
|
WithColor::error() << "reproducer capture failed: " << error << '\n';
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
const char *error = SBReproducer::Capture();
|
|
|
|
if (error) {
|
|
|
|
WithColor::error() << "reproducer capture failed: " << error << '\n';
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2020-07-10 01:35:16 +08:00
|
|
|
if (generate_on_exit)
|
2020-01-16 11:44:46 +08:00
|
|
|
SBReproducer::SetAutoGenerate(true);
|
2019-03-13 00:44:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return llvm::None;
|
|
|
|
}
|
|
|
|
|
2019-11-20 02:23:35 +08:00
|
|
|
int main(int argc, char const *argv[]) {
|
2021-07-13 18:37:53 +08:00
|
|
|
// Editline uses for example iswprint which is dependent on LC_CTYPE.
|
|
|
|
std::setlocale(LC_ALL, "");
|
|
|
|
std::setlocale(LC_CTYPE, "");
|
|
|
|
|
2019-11-14 09:23:21 +08:00
|
|
|
// Setup LLVM signal handlers and make sure we call llvm_shutdown() on
|
|
|
|
// destruction.
|
2019-11-15 06:30:56 +08:00
|
|
|
llvm::InitLLVM IL(argc, argv, /*InstallPipeSignalExitHandler=*/false);
|
2010-09-10 01:45:09 +08:00
|
|
|
|
2018-11-28 05:00:32 +08:00
|
|
|
// Parse arguments.
|
|
|
|
LLDBOptTable T;
|
2020-07-31 00:08:13 +08:00
|
|
|
unsigned MissingArgIndex;
|
|
|
|
unsigned MissingArgCount;
|
2018-11-28 05:00:32 +08:00
|
|
|
ArrayRef<const char *> arg_arr = makeArrayRef(argv + 1, argc - 1);
|
2020-07-31 00:08:13 +08:00
|
|
|
opt::InputArgList input_args =
|
|
|
|
T.ParseArgs(arg_arr, MissingArgIndex, MissingArgCount);
|
2020-05-21 03:32:41 +08:00
|
|
|
llvm::StringRef argv0 = llvm::sys::path::filename(argv[0]);
|
2010-06-23 09:19:29 +08:00
|
|
|
|
2018-11-28 05:00:32 +08:00
|
|
|
if (input_args.hasArg(OPT_help)) {
|
2020-05-21 03:32:41 +08:00
|
|
|
printHelp(T, argv0);
|
2018-11-28 05:00:32 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-31 00:08:13 +08:00
|
|
|
// Check for missing argument error.
|
|
|
|
if (MissingArgCount) {
|
|
|
|
WithColor::error() << "argument to '"
|
|
|
|
<< input_args.getArgString(MissingArgIndex)
|
|
|
|
<< "' is missing\n";
|
|
|
|
}
|
2020-05-21 00:21:45 +08:00
|
|
|
// Error out on unknown options.
|
|
|
|
if (input_args.hasArg(OPT_UNKNOWN)) {
|
|
|
|
for (auto *arg : input_args.filtered(OPT_UNKNOWN)) {
|
|
|
|
WithColor::error() << "unknown option: " << arg->getSpelling() << '\n';
|
|
|
|
}
|
2020-07-31 00:08:13 +08:00
|
|
|
}
|
|
|
|
if (MissingArgCount || input_args.hasArg(OPT_UNKNOWN)) {
|
2020-05-21 03:32:41 +08:00
|
|
|
llvm::errs() << "Use '" << argv0
|
|
|
|
<< " --help' for a complete list of options.\n";
|
2020-05-21 00:21:45 +08:00
|
|
|
return 1;
|
2018-11-29 06:39:17 +08:00
|
|
|
}
|
|
|
|
|
2020-07-10 02:47:56 +08:00
|
|
|
if (auto exit_code = InitializeReproducer(argv[0], input_args)) {
|
2019-03-13 00:44:18 +08:00
|
|
|
return *exit_code;
|
2018-12-04 01:28:29 +08:00
|
|
|
}
|
|
|
|
|
2019-02-22 06:26:16 +08:00
|
|
|
SBError error = SBDebugger::InitializeWithErrorHandling();
|
2018-12-04 01:28:29 +08:00
|
|
|
if (error.Fail()) {
|
|
|
|
WithColor::error() << "initialization failed: " << error.GetCString()
|
|
|
|
<< '\n';
|
|
|
|
return 1;
|
|
|
|
}
|
2016-03-23 01:58:09 +08:00
|
|
|
SBHostOS::ThreadCreated("<lldb.driver.main-thread>");
|
|
|
|
|
|
|
|
signal(SIGINT, sigint_handler);
|
2022-03-25 23:39:48 +08:00
|
|
|
#if !defined(_WIN32)
|
2016-03-23 01:58:09 +08:00
|
|
|
signal(SIGPIPE, SIG_IGN);
|
|
|
|
signal(SIGWINCH, sigwinch_handler);
|
|
|
|
signal(SIGTSTP, sigtstp_handler);
|
|
|
|
#endif
|
|
|
|
|
2018-07-12 01:18:01 +08:00
|
|
|
int exit_code = 0;
|
2016-03-23 01:58:09 +08:00
|
|
|
// Create a scope for driver so that the driver object will destroy itself
|
|
|
|
// before SBDebugger::Terminate() is called.
|
2010-06-23 09:19:29 +08:00
|
|
|
{
|
2016-03-23 01:58:09 +08:00
|
|
|
Driver driver;
|
2016-09-07 04:57:50 +08:00
|
|
|
|
2016-03-23 01:58:09 +08:00
|
|
|
bool exiting = false;
|
2018-11-29 06:39:17 +08:00
|
|
|
SBError error(driver.ProcessArgs(input_args, exiting));
|
2016-03-23 01:58:09 +08:00
|
|
|
if (error.Fail()) {
|
2018-07-12 01:18:01 +08:00
|
|
|
exit_code = 1;
|
2018-11-29 06:39:17 +08:00
|
|
|
if (const char *error_cstr = error.GetCString())
|
|
|
|
WithColor::error() << error_cstr << '\n';
|
2016-03-23 01:58:09 +08:00
|
|
|
} else if (!exiting) {
|
2018-07-12 01:18:01 +08:00
|
|
|
exit_code = driver.MainLoop();
|
2016-03-23 01:58:09 +08:00
|
|
|
}
|
2010-06-23 09:19:29 +08:00
|
|
|
}
|
2010-06-09 00:52:24 +08:00
|
|
|
|
2016-03-23 01:58:09 +08:00
|
|
|
SBDebugger::Terminate();
|
2018-07-12 01:18:01 +08:00
|
|
|
return exit_code;
|
2010-06-09 00:52:24 +08:00
|
|
|
}
|