mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
get minimal roc_dbg
working
This commit is contained in:
parent
b7f72eff86
commit
3d6c140a30
6 changed files with 69 additions and 29 deletions
|
@ -230,6 +230,7 @@ comptime {
|
|||
|
||||
// Utils
|
||||
comptime {
|
||||
exportUtilsFn(utils.test_dbg, "test_dbg");
|
||||
exportUtilsFn(utils.test_panic, "test_panic");
|
||||
exportUtilsFn(utils.increfRcPtrC, "incref_rc_ptr");
|
||||
exportUtilsFn(utils.decrefRcPtrC, "decref_rc_ptr");
|
||||
|
@ -248,7 +249,6 @@ comptime {
|
|||
exportUtilsFn(expect.expectFailedStartSharedBuffer, "expect_failed_start_shared_buffer");
|
||||
exportUtilsFn(expect.expectFailedStartSharedFile, "expect_failed_start_shared_file");
|
||||
exportUtilsFn(expect.notifyParentExpect, "notify_parent_expect");
|
||||
exportUtilsFn(expect.notifyParentDbg, "notify_parent_dbg");
|
||||
|
||||
// sets the buffer used for expect failures
|
||||
@export(expect.setSharedBuffer, .{ .name = "set_shared_buffer", .linkage = .Weak });
|
||||
|
|
|
@ -20,6 +20,13 @@ extern fn roc_realloc(c_ptr: *anyopaque, new_size: usize, old_size: usize, align
|
|||
// This should never be passed a null pointer.
|
||||
extern fn roc_dealloc(c_ptr: *anyopaque, alignment: u32) callconv(.C) void;
|
||||
|
||||
extern fn roc_dbg(file_path: *anyopaque, message: *anyopaque) callconv(.C) void;
|
||||
|
||||
// Since roc_dbg is never used by the builtins, we need at export a function that uses it to stop DCE.
|
||||
pub fn test_dbg(file_path: *anyopaque, message: *anyopaque) callconv(.C) void {
|
||||
roc_dbg(file_path, message);
|
||||
}
|
||||
|
||||
extern fn kill(pid: c_int, sig: c_int) c_int;
|
||||
extern fn shm_open(name: *const i8, oflag: c_int, mode: c_uint) c_int;
|
||||
extern fn mmap(addr: ?*anyopaque, length: c_uint, prot: c_int, flags: c_int, fd: c_int, offset: c_uint) *anyopaque;
|
||||
|
@ -40,6 +47,11 @@ fn testing_roc_mmap(addr: ?*anyopaque, length: c_uint, prot: c_int, flags: c_int
|
|||
return mmap(addr, length, prot, flags, fd, offset);
|
||||
}
|
||||
|
||||
fn testing_roc_dbg(file_path: *anyopaque, message: *anyopaque) callconv(.C) void {
|
||||
_ = message;
|
||||
_ = file_path;
|
||||
}
|
||||
|
||||
comptime {
|
||||
// During tests, use the testing allocators to satisfy these functions.
|
||||
if (builtin.is_test) {
|
||||
|
@ -47,6 +59,7 @@ comptime {
|
|||
@export(testing_roc_realloc, .{ .name = "roc_realloc", .linkage = .Strong });
|
||||
@export(testing_roc_dealloc, .{ .name = "roc_dealloc", .linkage = .Strong });
|
||||
@export(testing_roc_panic, .{ .name = "roc_panic", .linkage = .Strong });
|
||||
@export(testing_roc_dbg, .{ .name = "roc_dbg", .linkage = .Strong });
|
||||
|
||||
if (builtin.os.tag == .macos or builtin.os.tag == .linux) {
|
||||
@export(testing_roc_getppid, .{ .name = "roc_getppid", .linkage = .Strong });
|
||||
|
|
|
@ -439,7 +439,6 @@ pub const UTILS_EXPECT_FAILED_START_SHARED_FILE: &str =
|
|||
"roc_builtins.utils.expect_failed_start_shared_file";
|
||||
pub const UTILS_EXPECT_READ_ENV_SHARED_BUFFER: &str = "roc_builtins.utils.read_env_shared_buffer";
|
||||
pub const NOTIFY_PARENT_EXPECT: &str = "roc_builtins.utils.notify_parent_expect";
|
||||
pub const NOTIFY_PARENT_DBG: &str = "roc_builtins.utils.notify_parent_dbg";
|
||||
|
||||
pub const UTILS_LONGJMP: &str = "longjmp";
|
||||
pub const UTILS_SETJMP: &str = "setjmp";
|
||||
|
|
|
@ -919,6 +919,51 @@ impl<'a, 'ctx, 'env> Env<'a, 'ctx, 'env> {
|
|||
call.set_call_convention(C_CALL_CONV);
|
||||
}
|
||||
|
||||
pub fn call_dbg(
|
||||
&self,
|
||||
env: &Env<'a, 'ctx, 'env>,
|
||||
file_path: BasicValueEnum<'ctx>,
|
||||
message: BasicValueEnum<'ctx>,
|
||||
) {
|
||||
let function = self.module.get_function("roc_dbg").unwrap();
|
||||
|
||||
let file = match env.target_info.ptr_width() {
|
||||
PtrWidth::Bytes4 => {
|
||||
// we need to pass the file_path by reference, but we currently hold the value.
|
||||
let alloca = env
|
||||
.builder
|
||||
.new_build_alloca(file_path.get_type(), "alloca_dbg_file_path");
|
||||
env.builder.new_build_store(alloca, file_path);
|
||||
alloca.into()
|
||||
}
|
||||
PtrWidth::Bytes8 => {
|
||||
// string is already held by reference
|
||||
file_path
|
||||
}
|
||||
};
|
||||
|
||||
let msg = match env.target_info.ptr_width() {
|
||||
PtrWidth::Bytes4 => {
|
||||
// we need to pass the message by reference, but we currently hold the value.
|
||||
let alloca = env
|
||||
.builder
|
||||
.new_build_alloca(message.get_type(), "alloca_dbg_msg");
|
||||
env.builder.new_build_store(alloca, message);
|
||||
alloca.into()
|
||||
}
|
||||
PtrWidth::Bytes8 => {
|
||||
// string is already held by reference
|
||||
message
|
||||
}
|
||||
};
|
||||
|
||||
let call = self
|
||||
.builder
|
||||
.new_build_call(function, &[file.into(), msg.into()], "roc_dbg");
|
||||
|
||||
call.set_call_convention(C_CALL_CONV);
|
||||
}
|
||||
|
||||
pub fn new_debug_info(module: &Module<'ctx>) -> (DebugInfoBuilder<'ctx>, DICompileUnit<'ctx>) {
|
||||
module.create_debug_info_builder(
|
||||
true,
|
||||
|
@ -3502,26 +3547,15 @@ pub(crate) fn build_exp_stmt<'a, 'ctx>(
|
|||
|
||||
Dbg {
|
||||
symbol,
|
||||
variable: specialized_var,
|
||||
variable: _,
|
||||
remainder,
|
||||
} => {
|
||||
if env.mode.runs_expects() {
|
||||
let shared_memory = crate::llvm::expect::SharedMemoryPointer::get(env);
|
||||
let region = unsafe { std::mem::transmute::<_, roc_region::all::Region>(*symbol) };
|
||||
|
||||
crate::llvm::expect::clone_to_shared_memory(
|
||||
env,
|
||||
layout_interner,
|
||||
scope,
|
||||
layout_ids,
|
||||
&shared_memory,
|
||||
*symbol,
|
||||
region,
|
||||
&[*symbol],
|
||||
&[*specialized_var],
|
||||
);
|
||||
|
||||
crate::llvm::expect::notify_parent_dbg(env, &shared_memory);
|
||||
// TODO: deal with filename and region
|
||||
// let region = unsafe { std::mem::transmute::<_, roc_region::all::Region>(*symbol) };
|
||||
let file_path = build_string_literal(env, parent, "TODO: add filepath here");
|
||||
let message = scope.load_symbol(symbol);
|
||||
env.call_dbg(env, file_path, message);
|
||||
}
|
||||
|
||||
build_exp_stmt(
|
||||
|
|
|
@ -150,16 +150,6 @@ pub(crate) fn notify_parent_expect(env: &Env, shared_memory: &SharedMemoryPointe
|
|||
);
|
||||
}
|
||||
|
||||
pub(crate) fn notify_parent_dbg(env: &Env, shared_memory: &SharedMemoryPointer) {
|
||||
let func = env.module.get_function(bitcode::NOTIFY_PARENT_DBG).unwrap();
|
||||
|
||||
env.builder.new_build_call(
|
||||
func,
|
||||
&[shared_memory.0.into()],
|
||||
"call_expect_failed_finalize",
|
||||
);
|
||||
}
|
||||
|
||||
// Shape of expect frame:
|
||||
//
|
||||
// ===
|
||||
|
|
|
@ -29,6 +29,10 @@ void roc_panic(void* ptr, unsigned int alignment) {
|
|||
exit(0);
|
||||
}
|
||||
|
||||
void roc_dbg(char* file_path, char* msg) {
|
||||
fprintf(stderr, "[%s] %s\n", file_path, msg);
|
||||
}
|
||||
|
||||
void* roc_memset(void* str, int c, size_t n) { return memset(str, c, n); }
|
||||
|
||||
int roc_shm_open(char* name, int oflag, int mode) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue