try to fix debugger issue

This commit is contained in:
water 2021-08-11 21:40:58 -04:00
parent 3fb5d71340
commit 688e291672
5 changed files with 576 additions and 507 deletions

View file

@ -57,6 +57,9 @@ bool Debugger::is_attached() const {
*/
void Debugger::detach() {
if (is_valid() && m_attached) {
if (!is_halted()) {
do_break();
}
stop_watcher();
xdbg::close_memory(m_debug_context.tid, &m_memory_handle);
xdbg::detach_and_resume(m_debug_context.tid);

View file

@ -17,7 +17,6 @@ TEST(Debugger, DebuggerBasicConnect) {
EXPECT_TRUE(compiler.get_debugger().is_valid());
EXPECT_TRUE(compiler.get_debugger().is_halted());
compiler.shutdown_target(); // will detach/unhalt, then send the usual shutdown message
// and now the child process should be done!
EXPECT_TRUE(wait(nullptr) >= 0);
}

View file

@ -1,4 +1,5 @@
#include <thread>
#include <memory>
#include "goalc/compiler/Compiler.h"
#include "test/goalc/framework/test_runner.h"
#include "gtest/gtest.h"
@ -6,40 +7,44 @@
class KernelTest : public testing::Test {
public:
static void SetUpTestSuite() {
shared_compiler = std::make_unique<SharedCompiler>();
printf("Building kernel...\n");
try {
// a macro in goal-lib.gc
compiler.run_front_end_on_string("(build-kernel)");
shared_compiler->compiler.run_front_end_on_string("(build-kernel)");
} catch (std::exception& e) {
fprintf(stderr, "caught exception %s\n", e.what());
EXPECT_TRUE(false);
}
printf("Starting GOAL Kernel...\n");
runtime_thread = std::thread(GoalTest::runtime_with_kernel);
runner.c = &compiler;
compiler.run_test_from_string("(set! *use-old-listener-print* #t)");
shared_compiler->runtime_thread = std::thread(GoalTest::runtime_with_kernel);
shared_compiler->runner.c = &shared_compiler->compiler;
shared_compiler->compiler.run_test_from_string("(set! *use-old-listener-print* #t)");
}
static void TearDownTestSuite() {
// send message to shutdown
compiler.shutdown_target();
shared_compiler->compiler.shutdown_target();
// wait for shutdown.
runtime_thread.join();
shared_compiler->runtime_thread.join();
shared_compiler.reset();
}
void SetUp() {}
void TearDown() {}
static std::thread runtime_thread;
static Compiler compiler;
static GoalTest::CompilerTestRunner runner;
struct SharedCompiler {
std::thread runtime_thread;
Compiler compiler;
GoalTest::CompilerTestRunner runner;
};
static std::unique_ptr<SharedCompiler> shared_compiler;
};
std::thread KernelTest::runtime_thread;
Compiler KernelTest::compiler;
GoalTest::CompilerTestRunner KernelTest::runner;
std::unique_ptr<KernelTest::SharedCompiler> KernelTest::shared_compiler;
namespace {
std::string send_code_and_get_multiple_responses(const std::string& code,
@ -65,8 +70,10 @@ std::string send_code_and_get_multiple_responses(const std::string& code,
} // namespace
TEST_F(KernelTest, Basic) {
runner.c->run_test_from_string("(ml \"test/goalc/source_templates/kernel/kernel-test.gc\")");
std::string result = send_code_and_get_multiple_responses("(kernel-test)", 10, &runner);
shared_compiler->runner.c->run_test_from_string(
"(ml \"test/goalc/source_templates/kernel/kernel-test.gc\")");
std::string result =
send_code_and_get_multiple_responses("(kernel-test)", 10, &shared_compiler->runner);
std::string expected =
"0\n"
@ -95,8 +102,10 @@ TEST_F(KernelTest, Basic) {
}
TEST_F(KernelTest, RunFunctionInProcess) {
runner.c->run_test_from_string("(ml \"test/goalc/source_templates/kernel/kernel-test.gc\")");
std::string result = send_code_and_get_multiple_responses("(kernel-test-2)", 1, &runner);
shared_compiler->runner.c->run_test_from_string(
"(ml \"test/goalc/source_templates/kernel/kernel-test.gc\")");
std::string result =
send_code_and_get_multiple_responses("(kernel-test-2)", 1, &shared_compiler->runner);
std::string expected =
"0\n"
@ -112,8 +121,10 @@ TEST_F(KernelTest, RunFunctionInProcess) {
}
TEST_F(KernelTest, StateAndXmm) {
runner.c->run_test_from_string("(ml \"test/goalc/source_templates/kernel/kernel-test.gc\")");
std::string result = send_code_and_get_multiple_responses("(state-test)", 5, &runner);
shared_compiler->runner.c->run_test_from_string(
"(ml \"test/goalc/source_templates/kernel/kernel-test.gc\")");
std::string result =
send_code_and_get_multiple_responses("(state-test)", 5, &shared_compiler->runner);
std::string expected =
"0\nenter wreck: 3 4 5 6\nwreck: 3 4 5 6\nenter check: 9 8 7 6\nrun xmm-check 12.3400 "
@ -124,8 +135,10 @@ TEST_F(KernelTest, StateAndXmm) {
}
TEST_F(KernelTest, ThrowXmm) {
runner.c->run_test_from_string("(ml \"test/goalc/source_templates/kernel/kernel-test.gc\")");
std::string result = send_code_and_get_multiple_responses("(throw-backup-test)", 1, &runner);
shared_compiler->runner.c->run_test_from_string(
"(ml \"test/goalc/source_templates/kernel/kernel-test.gc\")");
std::string result =
send_code_and_get_multiple_responses("(throw-backup-test)", 1, &shared_compiler->runner);
std::string expected =
"value now is 10.1000\n"

View file

@ -25,13 +25,15 @@ struct VariableParam {
class VariableTests : public testing::TestWithParam<VariableParam> {
public:
static void SetUpTestSuite() {
runtime_thread = std::thread((GoalTest::runtime_no_kernel));
runner.c = &compiler;
shared_compiler = std::make_unique<SharedCompiler>();
shared_compiler->runtime_thread = std::thread((GoalTest::runtime_no_kernel));
shared_compiler->runner.c = &shared_compiler->compiler;
}
static void TearDownTestSuite() {
compiler.shutdown_target();
runtime_thread.join();
shared_compiler->compiler.shutdown_target();
shared_compiler->runtime_thread.join();
shared_compiler.reset();
}
void SetUp() {
@ -41,91 +43,100 @@ class VariableTests : public testing::TestWithParam<VariableParam> {
void TearDown() {}
static std::thread runtime_thread;
static Compiler compiler;
static GoalTest::CompilerTestRunner runner;
struct SharedCompiler {
std::thread runtime_thread;
Compiler compiler;
GoalTest::CompilerTestRunner runner;
};
static std::unique_ptr<SharedCompiler> shared_compiler;
std::string testCategory = "variables";
inja::Environment env{GoalTest::getTemplateDir(testCategory),
GoalTest::getGeneratedDir(testCategory)};
};
std::thread VariableTests::runtime_thread;
Compiler VariableTests::compiler;
GoalTest::CompilerTestRunner VariableTests::runner;
std::unique_ptr<VariableTests::SharedCompiler> VariableTests::shared_compiler;
TEST_F(VariableTests, Globals) {
runner.run_static_test(env, testCategory, "defglobalconstant-1.static.gc", {"17\n"});
runner.run_static_test(env, testCategory, "defglobalconstant-2.static.gc", {"18\n"});
shared_compiler->runner.run_static_test(env, testCategory, "defglobalconstant-1.static.gc",
{"17\n"});
shared_compiler->runner.run_static_test(env, testCategory, "defglobalconstant-2.static.gc",
{"18\n"});
}
TEST_F(VariableTests, Definitions) {
runner.run_static_test(env, testCategory, "define.static.gc", {"17\n"});
shared_compiler->runner.run_static_test(env, testCategory, "define.static.gc", {"17\n"});
}
TEST_F(VariableTests, Let) {
runner.run_static_test(env, testCategory, "let.static.gc", {"30\n"});
runner.run_static_test(env, testCategory, "let-star.static.gc", {"30\n"});
runner.run_static_test(env, testCategory, "mlet.static.gc", {"10\n"});
shared_compiler->runner.run_static_test(env, testCategory, "let.static.gc", {"30\n"});
shared_compiler->runner.run_static_test(env, testCategory, "let-star.static.gc", {"30\n"});
shared_compiler->runner.run_static_test(env, testCategory, "mlet.static.gc", {"10\n"});
}
TEST_F(VariableTests, StackVars) {
runner.run_static_test(env, testCategory, "stack-ints.gc", {"12\n"});
runner.run_static_test(env, testCategory, "stack-ints-2.gc", {"1\n"});
shared_compiler->runner.run_static_test(env, testCategory, "stack-ints.gc", {"12\n"});
shared_compiler->runner.run_static_test(env, testCategory, "stack-ints-2.gc", {"1\n"});
}
TEST_F(VariableTests, Bitfields) {
runner.run_static_test(env, testCategory, "bitfield-enums.gc", {"5\n"});
runner.run_static_test(env, testCategory, "integer-enums.gc", {"11\n"});
shared_compiler->runner.run_static_test(env, testCategory, "bitfield-enums.gc", {"5\n"});
shared_compiler->runner.run_static_test(env, testCategory, "integer-enums.gc", {"11\n"});
}
TEST_F(VariableTests, InlineAsm) {
runner.run_static_test(env, testCategory, "inline-asm.static.gc", {"1\n"});
shared_compiler->runner.run_static_test(env, testCategory, "inline-asm.static.gc", {"1\n"});
}
TEST_F(VariableTests, StaticBitfieldField) {
runner.run_static_test(env, testCategory, "static-bitfield-field.gc", {"22\n"});
shared_compiler->runner.run_static_test(env, testCategory, "static-bitfield-field.gc", {"22\n"});
}
TEST_F(VariableTests, StackArrayAlignment) {
runner.run_static_test(env, testCategory, "stack-array-align.gc", {"3\n"});
shared_compiler->runner.run_static_test(env, testCategory, "stack-array-align.gc", {"3\n"});
}
TEST_F(VariableTests, StackStructureAlignment) {
runner.run_static_test(env, testCategory, "stack-structure-align.gc", {"1234\n"});
shared_compiler->runner.run_static_test(env, testCategory, "stack-structure-align.gc",
{"1234\n"});
}
TEST_F(VariableTests, GetSymbol) {
runner.run_static_test(env, testCategory, "get-symbol-1.static.gc",
{"1342756\n"}); // 0x147d24 in hex
runner.run_static_test(env, testCategory, "get-symbol-2.static.gc",
{"1342764\n"}); // 0x147d2c in hex
shared_compiler->runner.run_static_test(env, testCategory, "get-symbol-1.static.gc",
{"1342756\n"}); // 0x147d24 in hex
shared_compiler->runner.run_static_test(env, testCategory, "get-symbol-2.static.gc",
{"1342764\n"}); // 0x147d2c in hex
}
TEST_F(VariableTests, Constants) {
// TODO - runner.run_static_test(env, testCategory, "string-constant-1.static.gc");
// TODO - shared_compiler->runner.run_static_test(env, testCategory,
// "string-constant-1.static.gc");
std::string expected = "\"test string!\"";
runner.run_static_test(env, testCategory, "string-constant-2.static.gc", {expected},
expected.size());
shared_compiler->runner.run_static_test(env, testCategory, "string-constant-2.static.gc",
{expected}, expected.size());
}
TEST_F(VariableTests, Symbols) {
runner.run_static_test(env, testCategory, "quote-symbol.static.gc", {"banana\n0\n"});
shared_compiler->runner.run_static_test(env, testCategory, "quote-symbol.static.gc",
{"banana\n0\n"});
std::string expected = "test-string";
runner.run_static_test(env, testCategory, "string-symbol.static.gc", {expected}, expected.size());
shared_compiler->runner.run_static_test(env, testCategory, "string-symbol.static.gc", {expected},
expected.size());
}
TEST_F(VariableTests, Formatting) {
runner.run_static_test(env, testCategory, "format-reg-order.static.gc",
{"test 1 2 3 4 5 6\n0\n"});
shared_compiler->runner.run_static_test(env, testCategory, "format-reg-order.static.gc",
{"test 1 2 3 4 5 6\n0\n"});
}
TEST_F(VariableTests, DeReference) {
runner.run_static_test(env, testCategory, "deref-simple.static.gc", {"structure\n0\n"});
shared_compiler->runner.run_static_test(env, testCategory, "deref-simple.static.gc",
{"structure\n0\n"});
}
TEST_F(VariableTests, Pointers) {
runner.run_static_test(env, testCategory, "pointers.static.gc", {"13\n"});
shared_compiler->runner.run_static_test(env, testCategory, "pointers.static.gc", {"13\n"});
}
// expected =
@ -141,4 +152,4 @@ TEST_F(VariableTests, Pointers) {
// expected += "test P (with type) 1447236\n";
//
// // todo, finish format testing.
// runner.run_test_from_file("test-format.gc", {expected}, expected.size());
// shared_compiler->runner.run_test_from_file("test-format.gc", {expected}, expected.size());

File diff suppressed because it is too large Load diff