windows widestring

This commit is contained in:
LemonBoy 2020-02-10 20:47:07 +01:00
parent 463f704431
commit b3f728585a

View File

@ -1255,13 +1255,14 @@ pub const DebugInfo = struct {
const seg_end = seg_start + info.SizeOfImage; const seg_end = seg_start + info.SizeOfImage;
if (address >= seg_start and address < seg_end) { if (address >= seg_start and address < seg_end) {
var name_buffer: [windows.MAX_PATH]u8 = undefined; var name_buffer: [windows.PATH_MAX_WIDE + 4:0]u16 = undefined;
// XXX: Use W variant (#534) // openFileAbsoluteW requires the prefix to be present
const len = windows.kernel32.K32GetModuleFileNameExA( mem.copy(u16, name_buffer[0..4], &[_]u16{ '\\', '?', '?', '\\' });
const len = windows.kernel32.K32GetModuleFileNameExW(
process_handle, process_handle,
module, module,
@ptrCast(windows.LPSTR, &name_buffer), @ptrCast(windows.LPWSTR, &name_buffer[4]),
@sizeOf(@TypeOf(name_buffer)) / @sizeOf(u8), windows.PATH_MAX_WIDE,
); );
assert(len > 0); assert(len > 0);
@ -1270,9 +1271,9 @@ pub const DebugInfo = struct {
} }
// XXX: The compiler segfaults if the slicing is done as a // XXX: The compiler segfaults if the slicing is done as a
// parameter // parameter (#4423)
const tmp = name_buffer[0..:0]; const tmp = name_buffer[0..:0];
const file_obj = try fs.cwd().openFileC(tmp, .{}); const file_obj = try fs.openFileAbsoluteW(tmp, .{});
errdefer file_obj.close(); errdefer file_obj.close();
const obj_di = try self.allocator.create(ObjectDebugInfo); const obj_di = try self.allocator.create(ObjectDebugInfo);
@ -1293,8 +1294,6 @@ pub const DebugInfo = struct {
fn lookupModuleDl(self: *DebugInfo, address: usize) !*ObjectDebugInfo { fn lookupModuleDl(self: *DebugInfo, address: usize) !*ObjectDebugInfo {
var ctx = DIPContext{ .address = address }; var ctx = DIPContext{ .address = address };
warn("lookup {x}\n", .{address});
// XXX Locking? // XXX Locking?
if (os.dl_iterate_phdr(DIPContext, dl_iterate_phdr_callback, &ctx) == 0) if (os.dl_iterate_phdr(DIPContext, dl_iterate_phdr_callback, &ctx) == 0)
return error.DebugInfoNotFound; return error.DebugInfoNotFound;