added 5 changesets to branch 'refs/remotes/xyzzy-github/x86_64' old head: 2997a1912589c1b6c3276eaa4ab797040cd69230 new head: a3802ca96702d7011ad4967428c38f196b07480c ---------------------------------------------------------------------------- c802257: Merge branch 'master' into x86_64 2b883e1: Fix compilation of OHCI on x86. Fixes were needed to go with the USB stack changes. Haven't tested it yet because I don't have a a machine with OHCI, but I doubt there will be any problems. 8a19033: Implemented user debugging support for x86_64. Reused x86 arch_user_debugger.cpp, with a few minor changes to make the code work for both 32 and 64 bit. Something isn't quite working right, if a breakpoint is hit the kernel will hang. Other than that everything appears to work correctly. a731ad1: ELF64 and x86_64 support in the debug kit. a3802ca: x86_64 support for GDB. As mentioned in one of the previous commits, breakpoints don't work properly yet, and I haven't done much extensive testing yet, but the basic functionality works. [ Alex Smith <alex@xxxxxxxxxxxxxxxx> ] ---------------------------------------------------------------------------- 353 files changed, 13072 insertions(+), 1403 deletions(-) build/jam/Haiku64Image | 10 +- .../inbound_filters/notifier/fr.catkeys | 2 +- .../outbound_filters/fortune/fr.catkeys | 2 +- .../add-ons/screen_savers/glife/fr.catkeys | 8 + .../add-ons/translators/jpeg2000/fr.catkeys | 2 +- data/catalogs/add-ons/translators/sgi/fr.catkeys | 2 +- data/catalogs/add-ons/translators/stxt/fr.catkeys | 2 +- data/catalogs/add-ons/translators/tiff/fr.catkeys | 2 +- .../add-ons/translators/wonderbrush/fr.catkeys | 2 +- data/catalogs/apps/aboutsystem/fr.catkeys | 4 +- data/catalogs/apps/aboutsystem/ru.catkeys | 6 +- data/catalogs/apps/activitymonitor/ru.catkeys | 4 +- data/catalogs/apps/bootmanager/ru.catkeys | 2 +- data/catalogs/apps/charactermap/fr.catkeys | 3 +- data/catalogs/apps/codycam/fr.catkeys | 12 +- data/catalogs/apps/deskbar/fr.catkeys | 12 +- data/catalogs/apps/deskcalc/de.catkeys | 4 +- data/catalogs/apps/deskcalc/fr.catkeys | 4 +- data/catalogs/apps/devices/fr.catkeys | 12 +- data/catalogs/apps/diskusage/fr.catkeys | 3 +- data/catalogs/apps/diskusage/ru.catkeys | 2 +- data/catalogs/apps/drivesetup/be.catkeys | 8 +- data/catalogs/apps/drivesetup/de.catkeys | 8 +- data/catalogs/apps/drivesetup/el.catkeys | 7 +- data/catalogs/apps/drivesetup/fi.catkeys | 8 +- data/catalogs/apps/drivesetup/fr.catkeys | 12 +- data/catalogs/apps/drivesetup/ja.catkeys | 8 +- data/catalogs/apps/drivesetup/lt.catkeys | 8 +- data/catalogs/apps/drivesetup/nb.catkeys | 8 +- data/catalogs/apps/drivesetup/nl.catkeys | 8 +- data/catalogs/apps/drivesetup/pl.catkeys | 8 +- data/catalogs/apps/drivesetup/ro.catkeys | 8 +- data/catalogs/apps/drivesetup/ru.catkeys | 14 +- data/catalogs/apps/drivesetup/sk.catkeys | 8 +- data/catalogs/apps/drivesetup/uk.catkeys | 6 +- data/catalogs/apps/drivesetup/zh-Hans.catkeys | 8 +- data/catalogs/apps/expander/fr.catkeys | 8 +- data/catalogs/apps/fontdemo/fr.catkeys | 20 + data/catalogs/apps/glteapot/fr.catkeys | 9 +- data/catalogs/apps/icon-o-matic/fr.catkeys | 2 +- data/catalogs/apps/installedpackages/fr.catkeys | 2 +- data/catalogs/apps/installer/fr.catkeys | 15 +- data/catalogs/apps/installer/ru.catkeys | 2 +- data/catalogs/apps/launchbox/fr.catkeys | 4 +- data/catalogs/apps/magnify/fr.catkeys | 13 +- data/catalogs/apps/mediaplayer/fr.catkeys | 45 +- data/catalogs/apps/midiplayer/fr.catkeys | 2 +- data/catalogs/apps/networkstatus/fr.catkeys | 3 +- data/catalogs/apps/packageinstaller/fr.catkeys | 8 +- data/catalogs/apps/packageinstaller/ru.catkeys | 7 +- data/catalogs/apps/people/fr.catkeys | 4 +- data/catalogs/apps/poorman/fr.catkeys | 12 +- data/catalogs/apps/powerstatus/fr.catkeys | 21 +- .../catalogs/apps/screenshot/Screenshot/fr.catkeys | 5 +- data/catalogs/apps/soundrecorder/fr.catkeys | 31 +- data/catalogs/apps/stylededit/fr.catkeys | 2 +- data/catalogs/apps/terminal/fr.catkeys | 8 +- data/catalogs/apps/tv/fr.catkeys | 4 +- data/catalogs/apps/webpositive/de.catkeys | 3 +- data/catalogs/apps/webpositive/fr.catkeys | 123 + data/catalogs/bin/desklink/fr.catkeys | 2 +- data/catalogs/bin/dstcheck/fr.catkeys | 2 +- data/catalogs/bin/filepanel/fr.catkeys | 2 +- data/catalogs/kits/ru.catkeys | 8 +- data/catalogs/kits/textencoding/fr.catkeys | 10 +- data/catalogs/kits/tracker/de.catkeys | 7 +- data/catalogs/kits/tracker/fr.catkeys | 8 +- data/catalogs/kits/tracker/ru.catkeys | 8 +- data/catalogs/preferences/3drendering/fr.catkeys | 6 +- data/catalogs/preferences/appearance/fr.catkeys | 5 +- data/catalogs/preferences/filetypes/ru.catkeys | 2 +- data/catalogs/preferences/keymap/fr.catkeys | 17 +- data/catalogs/preferences/mail/fr.catkeys | 16 +- data/catalogs/preferences/media/fr.catkeys | 4 +- data/catalogs/preferences/notifications/fr.catkeys | 6 +- data/catalogs/preferences/printers/ru.catkeys | 2 +- data/catalogs/preferences/shortcuts/fr.catkeys | 6 +- data/catalogs/preferences/time/fr.catkeys | 4 +- data/catalogs/preferences/virtualmemory/ru.catkeys | 6 +- data/catalogs/servers/notification/fr.catkeys | 2 +- data/catalogs/tests/kits/game/chart/fr.catkeys | 11 +- headers/os/arch/x86_64/arch_debugger.h | 4 +- headers/os/translation/TranslationUtils.h | 3 + headers/private/graphics/common/dp.h | 5 +- headers/private/kernel/arch/x86/arch_cpu.h | 4 +- .../private/kernel/arch/x86/arch_user_debugger.h | 14 +- headers/private/kernel/elf.h | 7 +- headers/private/system/syscalls.h | 4 +- src/add-ons/accelerants/common/dp.cpp | 35 +- src/add-ons/accelerants/radeon_hd/displayport.cpp | 80 +- src/add-ons/accelerants/radeon_hd/displayport.h | 5 +- src/add-ons/accelerants/radeon_hd/mode.cpp | 12 +- src/add-ons/accelerants/radeon_hd/pll.cpp | 12 +- src/add-ons/accelerants/radeon_hd/pll.h | 5 +- .../filters/shortcut_catcher/CommandActuators.cpp | 15 +- .../input_server/methods/canna/CannaLooper.cpp | 1 + .../methods/pen/PenInputServerMethod.cpp | 1 + .../methods/t9/DictionaryInputServerMethod.cpp | 1 + .../methods/t9/T9InputServerMethod.cpp | 1 + [ *** stats truncated: 254 lines dropped *** ] ############################################################################ Commit: c802257bbba0cf2161957bcb0421290ff9eb1286 Author: Alex Smith <alex@xxxxxxxxxxxxxxxx> Date: Mon Aug 6 11:34:03 2012 UTC Merge branch 'master' into x86_64 ---------------------------------------------------------------------------- ############################################################################ Commit: 2b883e1977b1c420935c80b6fb9eb0067f112301 Author: Alex Smith <alex@xxxxxxxxxxxxxxxx> Date: Mon Aug 6 16:25:51 2012 UTC Fix compilation of OHCI on x86. Fixes were needed to go with the USB stack changes. Haven't tested it yet because I don't have a a machine with OHCI, but I doubt there will be any problems. ---------------------------------------------------------------------------- diff --git a/src/add-ons/kernel/busses/usb/ehci.cpp b/src/add-ons/kernel/busses/usb/ehci.cpp index 4427448..1a93c63 100644 --- a/src/add-ons/kernel/busses/usb/ehci.cpp +++ b/src/add-ons/kernel/busses/usb/ehci.cpp @@ -388,8 +388,11 @@ EHCI::EHCI(pci_info *info, Stack *stack) return; } - if ((physicalAddress & 0xfff) != 0) - panic("EHCI_PERIODICLISTBASE not aligned on 4k: 0x%lx\n", physicalAddress); + if ((physicalAddress & 0xfff) != 0) { + panic("EHCI_PERIODICLISTBASE not aligned on 4k: 0x%" B_PRIxPHYSADDR + "\n", physicalAddress); + } + // set the periodic frame list base on the controller WriteOpReg(EHCI_PERIODICLISTBASE, (uint32)physicalAddress); diff --git a/src/add-ons/kernel/busses/usb/ohci.cpp b/src/add-ons/kernel/busses/usb/ohci.cpp index c9f2c1a..8e31de4 100644 --- a/src/add-ons/kernel/busses/usb/ohci.cpp +++ b/src/add-ons/kernel/busses/usb/ohci.cpp @@ -99,7 +99,7 @@ OHCI::OHCI(pci_info *info, Stack *stack) uint32 offset = sPCIModule->read_pci_config(fPCIInfo->bus, fPCIInfo->device, fPCIInfo->function, PCI_base_registers, 4); offset &= PCI_address_memory_32_mask; - TRACE_ALWAYS("iospace offset: 0x%lx\n", offset); + TRACE_ALWAYS("iospace offset: 0x%" B_PRIx32 "\n", offset); fRegisterArea = map_physical_memory("OHCI memory mapped registers", offset, B_PAGE_SIZE, B_ANY_KERNEL_BLOCK_ADDRESS, B_KERNEL_READ_AREA | B_KERNEL_WRITE_AREA | B_READ_AREA | B_WRITE_AREA, @@ -121,7 +121,7 @@ OHCI::OHCI(pci_info *info, Stack *stack) return; } - void *hccaPhysicalAddress; + phys_addr_t hccaPhysicalAddress; fHccaArea = fStack->AllocateArea((void **)&fHcca, &hccaPhysicalAddress, sizeof(ohci_hcca), "USB OHCI Host Controller Communication Area"); @@ -165,7 +165,8 @@ OHCI::OHCI(pci_info *info, Stack *stack) for (int32 i = 0; i < OHCI_STATIC_ENDPOINT_COUNT; i++) { fInterruptEndpoints[i] = _AllocateEndpoint(); if (!fInterruptEndpoints[i]) { - TRACE_ERROR("failed to allocate interrupt endpoint %ld", i); + TRACE_ERROR("failed to allocate interrupt endpoint %" B_PRId32 "\n", + i); while (--i >= 0) _FreeEndpoint(fInterruptEndpoints[i]); _FreeEndpoint(fDummyBulk); @@ -362,7 +363,7 @@ OHCI::Start() uint32 control = _ReadReg(OHCI_CONTROL); if ((control & OHCI_HC_FUNCTIONAL_STATE_MASK) != OHCI_HC_FUNCTIONAL_STATE_OPERATIONAL) { - TRACE_ERROR("controller not started (0x%08lx)!\n", control); + TRACE_ERROR("controller not started (0x%08" B_PRIx32 ")!\n", control); return B_ERROR; } else TRACE("controller is operational!\n"); @@ -409,7 +410,8 @@ OHCI::SubmitTransfer(Transfer *transfer) return _SubmitIsochronousTransfer(transfer); } - TRACE_ERROR("tried to submit transfer for unknown pipe type %lu\n", type); + TRACE_ERROR("tried to submit transfer for unknown pipe type %" B_PRIu32 "\n", + type); return B_ERROR; } @@ -485,7 +487,7 @@ OHCI::CancelQueuedTransfers(Pipe *pipe, bool force) status_t OHCI::NotifyPipeChange(Pipe *pipe, usb_change change) { - TRACE("pipe change %d for pipe 0x%08lx\n", change, (uint32)pipe); + TRACE("pipe change %d for pipe %p\n", change, pipe); if (pipe->DeviceAddress() == fRootHubAddress) { // no need to insert/remove endpoint descriptors for the root hub return B_OK; @@ -524,7 +526,8 @@ OHCI::AddTo(Stack *stack) if (!sPCIModule) { status_t status = get_module(B_PCI_MODULE_NAME, (module_info **)&sPCIModule); if (status < B_OK) { - TRACE_MODULE_ERROR("getting pci module failed! 0x%08lx\n", status); + TRACE_MODULE_ERROR("getting pci module failed! 0x%08" B_PRIx32 "\n", + status); return status; } } @@ -926,7 +929,7 @@ OHCI::_FinishTransfers() // was halted because of this td, but we do not need // to know, as when it was halted by another td this // still ensures that this td was handled before). - TRACE_ERROR("td error: 0x%08lx\n", status); + TRACE_ERROR("td error: 0x%08" B_PRIx32 "\n", status); switch (status) { case OHCI_TD_CONDITION_CRC_ERROR: @@ -1036,7 +1039,7 @@ OHCI::_FinishTransfers() // break the descriptor chain on the last descriptor transfer->last_descriptor->next_logical_descriptor = NULL; - TRACE("transfer %p done with status 0x%08lx\n", + TRACE("transfer %p done with status 0x%08" B_PRIx32 "\n", transfer, callbackStatus); // if canceled the callback has already been called @@ -1326,7 +1329,7 @@ ohci_endpoint_descriptor * OHCI::_AllocateEndpoint() { ohci_endpoint_descriptor *endpoint; - void *physicalAddress; + phys_addr_t physicalAddress; mutex *lock = (mutex *)malloc(sizeof(mutex)); if (lock == NULL) { @@ -1345,7 +1348,7 @@ OHCI::_AllocateEndpoint() mutex_init(lock, "ohci endpoint lock"); endpoint->flags = OHCI_ENDPOINT_SKIP; - endpoint->physical_address = (addr_t)physicalAddress; + endpoint->physical_address = (uint32)physicalAddress; endpoint->head_physical_descriptor = 0; endpoint->tail_logical_descriptor = NULL; endpoint->tail_physical_descriptor = 0; @@ -1365,7 +1368,7 @@ OHCI::_FreeEndpoint(ohci_endpoint_descriptor *endpoint) mutex_destroy(endpoint->lock); free(endpoint->lock); - fStack->FreeChunk((void *)endpoint, (void *)endpoint->physical_address, + fStack->FreeChunk((void *)endpoint, endpoint->physical_address, sizeof(ohci_endpoint_descriptor)); } @@ -1522,7 +1525,7 @@ ohci_general_td * OHCI::_CreateGeneralDescriptor(size_t bufferSize) { ohci_general_td *descriptor; - void *physicalAddress; + phys_addr_t physicalAddress; if (fStack->AllocateChunk((void **)&descriptor, &physicalAddress, sizeof(ohci_general_td)) != B_OK) { @@ -1530,7 +1533,7 @@ OHCI::_CreateGeneralDescriptor(size_t bufferSize) return NULL; } - descriptor->physical_address = (addr_t)physicalAddress; + descriptor->physical_address = (uint32)physicalAddress; descriptor->next_physical_descriptor = 0; descriptor->next_logical_descriptor = NULL; descriptor->buffer_size = bufferSize; @@ -1542,12 +1545,13 @@ OHCI::_CreateGeneralDescriptor(size_t bufferSize) } if (fStack->AllocateChunk(&descriptor->buffer_logical, - (void **)&descriptor->buffer_physical, bufferSize) != B_OK) { + &physicalAddress, bufferSize) != B_OK) { TRACE_ERROR("failed to allocate space for buffer\n"); - fStack->FreeChunk(descriptor, (void *)descriptor->physical_address, + fStack->FreeChunk(descriptor, descriptor->physical_address, sizeof(ohci_general_td)); return NULL; } + descriptor->buffer_physical = physicalAddress; descriptor->last_physical_byte_address = descriptor->buffer_physical + bufferSize - 1; @@ -1563,10 +1567,10 @@ OHCI::_FreeGeneralDescriptor(ohci_general_td *descriptor) if (descriptor->buffer_logical) { fStack->FreeChunk(descriptor->buffer_logical, - (void *)descriptor->buffer_physical, descriptor->buffer_size); + descriptor->buffer_physical, descriptor->buffer_size); } - fStack->FreeChunk((void *)descriptor, (void *)descriptor->physical_address, + fStack->FreeChunk((void *)descriptor, descriptor->physical_address, sizeof(ohci_general_td)); } @@ -1819,11 +1823,11 @@ void OHCI::_PrintEndpoint(ohci_endpoint_descriptor *endpoint) { TRACE_ALWAYS("endpoint %p\n", endpoint); - dprintf("\tflags........... 0x%08lx\n", endpoint->flags); - dprintf("\ttail_physical... 0x%08lx\n", endpoint->tail_physical_descriptor); - dprintf("\thead_physical... 0x%08lx\n", endpoint->head_physical_descriptor); - dprintf("\tnext_physical... 0x%08lx\n", endpoint->next_physical_endpoint); - dprintf("\tphysical........ 0x%08lx\n", endpoint->physical_address); + dprintf("\tflags........... 0x%08" B_PRIx32 "\n", endpoint->flags); + dprintf("\ttail_physical... 0x%08" B_PRIx32 "\n", endpoint->tail_physical_descriptor); + dprintf("\thead_physical... 0x%08" B_PRIx32 "\n", endpoint->head_physical_descriptor); + dprintf("\tnext_physical... 0x%08" B_PRIx32 "\n", endpoint->next_physical_endpoint); + dprintf("\tphysical........ 0x%08" B_PRIx32 "\n", endpoint->physical_address); dprintf("\ttail_logical.... %p\n", endpoint->tail_logical_descriptor); dprintf("\tnext_logical.... %p\n", endpoint->next_logical_endpoint); } @@ -1834,11 +1838,11 @@ OHCI::_PrintDescriptorChain(ohci_general_td *topDescriptor) { while (topDescriptor) { TRACE_ALWAYS("descriptor %p\n", topDescriptor); - dprintf("\tflags........... 0x%08lx\n", topDescriptor->flags); - dprintf("\tbuffer_physical. 0x%08lx\n", topDescriptor->buffer_physical); - dprintf("\tnext_physical... 0x%08lx\n", topDescriptor->next_physical_descriptor); - dprintf("\tlast_byte....... 0x%08lx\n", topDescriptor->last_physical_byte_address); - dprintf("\tphysical........ 0x%08lx\n", topDescriptor->physical_address); + dprintf("\tflags........... 0x%08" B_PRIx32 "\n", topDescriptor->flags); + dprintf("\tbuffer_physical. 0x%08" B_PRIx32 "\n", topDescriptor->buffer_physical); + dprintf("\tnext_physical... 0x%08" B_PRIx32 "\n", topDescriptor->next_physical_descriptor); + dprintf("\tlast_byte....... 0x%08" B_PRIx32 "\n", topDescriptor->last_physical_byte_address); + dprintf("\tphysical........ 0x%08" B_PRIx32 "\n", topDescriptor->physical_address); dprintf("\tbuffer_size..... %lu\n", topDescriptor->buffer_size); dprintf("\tbuffer_logical.. %p\n", topDescriptor->buffer_logical); dprintf("\tnext_logical.... %p\n", topDescriptor->next_logical_descriptor); diff --git a/src/add-ons/kernel/busses/usb/ohci_hardware.h b/src/add-ons/kernel/busses/usb/ohci_hardware.h index e98575f..308a27b 100644 --- a/src/add-ons/kernel/busses/usb/ohci_hardware.h +++ b/src/add-ons/kernel/busses/usb/ohci_hardware.h @@ -301,7 +301,7 @@ typedef struct { uint32 head_physical_descriptor; // Queue head physical pointer uint32 next_physical_endpoint; // Physical pointer to the next endpoint // Software part - addr_t physical_address; // Physical pointer to this address + uint32 physical_address; // Physical pointer to this address void *tail_logical_descriptor; // Queue tail logical pointer void *next_logical_endpoint; // Logical pointer to the next endpoint mutex *lock; // Protects tail changes and checks @@ -340,7 +340,7 @@ typedef struct { uint32 next_physical_descriptor; // Physical pointer next descriptor uint32 last_physical_byte_address; // Physical pointer to buffer end // Software part - addr_t physical_address; // Physical address of this descriptor + uint32 physical_address; // Physical address of this descriptor size_t buffer_size; // Size of the buffer void *buffer_logical; // Logical pointer to the buffer void *next_logical_descriptor; // Logical pointer next descriptor @@ -395,7 +395,7 @@ typedef struct { uint32 last_byte_address; // Physical buffer end uint16 offset[OHCI_ITD_NOFFSET]; // Buffer offsets // Software part - addr_t physical_address; // Physical address of this descriptor + uint32 physical_address; // Physical address of this descriptor void *next_logical_descriptor; // Logical pointer next descriptor void *next_done_descriptor; // Used for collision in the hash table } ohci_isochronous_td; ############################################################################ Commit: 8a1903353eedd95266c7241aada3a314c5d35a55 Author: Alex Smith <alex@xxxxxxxxxxxxxxxx> Date: Tue Aug 7 19:20:42 2012 UTC Implemented user debugging support for x86_64. Reused x86 arch_user_debugger.cpp, with a few minor changes to make the code work for both 32 and 64 bit. Something isn't quite working right, if a breakpoint is hit the kernel will hang. Other than that everything appears to work correctly. ---------------------------------------------------------------------------- diff --git a/headers/os/arch/x86_64/arch_debugger.h b/headers/os/arch/x86_64/arch_debugger.h index 5b9220b..59b27c3 100644 --- a/headers/os/arch/x86_64/arch_debugger.h +++ b/headers/os/arch/x86_64/arch_debugger.h @@ -32,7 +32,7 @@ typedef struct x86_64_extended_registers { x86_64_fp_register mmx_registers[8]; // mm0-mm7 }; x86_64_xmm_register xmm_registers[16]; // xmm0-xmm15 - uint8 reserved4[96]; // 416 - 512 + uint8 reserved2[96]; // 416 - 512 } x86_64_extended_registers; @@ -58,8 +58,6 @@ struct x86_64_debug_cpu_state { uint64 rcx; uint64 rbx; uint64 rax; - uint64 vector; - uint64 error_code; uint64 rip; uint64 cs; uint64 rflags; diff --git a/headers/private/kernel/arch/x86/arch_cpu.h b/headers/private/kernel/arch/x86/arch_cpu.h index dc0bafa..47d87b1 100644 --- a/headers/private/kernel/arch/x86/arch_cpu.h +++ b/headers/private/kernel/arch/x86/arch_cpu.h @@ -263,8 +263,8 @@ typedef struct arch_cpu_info { struct X86PagingStructures* active_paging_structures; - uint32 dr6; // temporary storage for debug registers (cf. - uint32 dr7; // x86_exit_user_debug_at_kernel_entry()) + size_t dr6; // temporary storage for debug registers (cf. + size_t dr7; // x86_exit_user_debug_at_kernel_entry()) // local TSS for this cpu struct tss tss; diff --git a/headers/private/kernel/arch/x86/arch_user_debugger.h b/headers/private/kernel/arch/x86/arch_user_debugger.h index 1b72d9b..01a98e7 100644 --- a/headers/private/kernel/arch/x86/arch_user_debugger.h +++ b/headers/private/kernel/arch/x86/arch_user_debugger.h @@ -9,8 +9,12 @@ #define ARCH_INIT_USER_DEBUG x86_init_user_debug // number of breakpoints the CPU supports -// Actually it supports 4, but DR3 is used to hold the Thread*. -#define X86_BREAKPOINT_COUNT 3 +// On 32-bit, DR3 is used to hold the Thread*. +#ifdef __x86_64__ +# define X86_BREAKPOINT_COUNT 4 +#else +# define X86_BREAKPOINT_COUNT 3 +#endif // debug status register DR6 enum { @@ -95,14 +99,14 @@ enum { struct arch_breakpoint { void *address; // NULL, if deactivated - uint32 type; // one of the architecture types above - uint32 length; // one of the length values above + size_t type; // one of the architecture types above + size_t length; // one of the length values above }; struct arch_team_debug_info { struct arch_breakpoint breakpoints[X86_BREAKPOINT_COUNT]; - uint32 dr7; // debug control register DR7 + size_t dr7; // debug control register DR7 }; struct arch_thread_debug_info { diff --git a/headers/private/kernel/elf.h b/headers/private/kernel/elf.h index 292cb9f..3851504 100644 --- a/headers/private/kernel/elf.h +++ b/headers/private/kernel/elf.h @@ -9,6 +9,7 @@ #define _KERNEL_ELF_H +#include <elf_common.h> #include <thread.h> #include <image.h> @@ -49,9 +50,9 @@ status_t elf_add_memory_image_symbol(image_id id, const char* name, addr_t address, size_t size, int32 type); status_t elf_init(struct kernel_args *args); -status_t _user_read_kernel_image_symbols(image_id id, - struct Elf32_Sym* symbolTable, int32* _symbolCount, - char* stringTable, size_t* _stringTableSize, addr_t* _imageDelta); +status_t _user_read_kernel_image_symbols(image_id id, elf_sym* symbolTable, + int32* _symbolCount, char* stringTable, size_t* _stringTableSize, + addr_t* _imageDelta); #ifdef __cplusplus } diff --git a/headers/private/system/syscalls.h b/headers/private/system/syscalls.h index 0e588b2..438a3ea 100644 --- a/headers/private/system/syscalls.h +++ b/headers/private/system/syscalls.h @@ -8,6 +8,7 @@ #include <arch_config.h> #include <DiskDeviceDefs.h> +#include <elf_common.h> #include <image.h> #include <OS.h> @@ -21,7 +22,6 @@ extern "C" { struct attr_info; struct dirent; -struct Elf32_Sym; struct fd_info; struct fd_set; struct fs_info; @@ -226,7 +226,7 @@ extern status_t _kern_get_image_info(image_id id, image_info *info, extern status_t _kern_get_next_image_info(team_id team, int32 *cookie, image_info *info, size_t size); extern status_t _kern_read_kernel_image_symbols(image_id id, - struct Elf32_Sym* symbolTable, int32* _symbolCount, + elf_sym* symbolTable, int32* _symbolCount, char* stringTable, size_t* _stringTableSize, addr_t* _imageDelta); diff --git a/src/system/kernel/arch/x86/64/int.cpp b/src/system/kernel/arch/x86/64/int.cpp index 1f43415..afffdf1 100644 --- a/src/system/kernel/arch/x86/64/int.cpp +++ b/src/system/kernel/arch/x86/64/int.cpp @@ -72,11 +72,9 @@ arch_int_init(kernel_args* args) table[i] = x86_hardware_interrupt; table[0] = x86_unexpected_exception; // Divide Error Exception (#DE) - //table[1] = x86_handle_debug_exception; // Debug Exception (#DB) - table[1] = x86_unexpected_exception; + table[1] = x86_handle_debug_exception; // Debug Exception (#DB) table[2] = x86_fatal_exception; // NMI Interrupt - //table[3] = x86_handle_breakpoint_exception; // Breakpoint Exception (#BP) - table[3] = x86_unexpected_exception; + table[3] = x86_handle_breakpoint_exception; // Breakpoint Exception (#BP) table[4] = x86_unexpected_exception; // Overflow Exception (#OF) table[5] = x86_unexpected_exception; // BOUND Range Exceeded Exception (#BR) table[6] = x86_unexpected_exception; // Invalid Opcode Exception (#UD) diff --git a/src/system/kernel/arch/x86/64/interrupts.S b/src/system/kernel/arch/x86/64/interrupts.S index 5f70ae2..b5157e1 100644 --- a/src/system/kernel/arch/x86/64/interrupts.S +++ b/src/system/kernel/arch/x86/64/interrupts.S @@ -109,17 +109,12 @@ \ UNLOCK_THREAD_TIME() -// TODO -#if 0 #define STOP_USER_DEBUGGING() \ testl $(THREAD_FLAGS_BREAKPOINTS_INSTALLED \ | THREAD_FLAGS_SINGLE_STEP), THREAD_flags(%r12); \ jz 1f; \ call x86_exit_user_debug_at_kernel_entry; \ 1: -#else -#define STOP_USER_DEBUGGING() -#endif // The following code defines the interrupt service routines for all 256 @@ -273,12 +268,12 @@ STATIC_FUNCTION(int_bottom_user): call thread_at_kernel_exit_no_signals .Lkernel_exit_work_done: - // Install breakpoints, if defined. TODO - //testl $THREAD_FLAGS_BREAKPOINTS_DEFINED, THREAD_flags(%r12) - //jz 1f - //movq %rbp, %rdi - //call x86_init_user_debug_at_kernel_exit -//1: + // Install breakpoints, if defined. + testl $THREAD_FLAGS_BREAKPOINTS_DEFINED, THREAD_flags(%r12) + jz 1f + movq %rbp, %rdi + call x86_init_user_debug_at_kernel_exit +1: // Restore the saved registers. RESTORE_IFRAME() @@ -333,7 +328,7 @@ FUNCTION(x86_64_syscall_entry): // Check whether the syscall number is valid. cmpq $SYSCALL_COUNT, %r14 - jae .Lbad_syscall_number + jae .Lsyscall_return // Get the system call table entry. Note I'm hardcoding the shift because // sizeof(syscall_info) is 16 and scale factors of 16 aren't supported, @@ -348,6 +343,11 @@ FUNCTION(x86_64_syscall_entry): cmpq $48, %rcx ja .Lsyscall_stack_args +.Lperform_syscall: + testl $THREAD_FLAGS_DEBUGGER_INSTALLED, THREAD_flags(%r12) + jnz .Lpre_syscall_debug + +.Lpre_syscall_debug_done: // Restore the arguments from the iframe. UPDATE_THREAD_USER_TIME() makes // 2 function calls which means they may have been overwritten. Note that // argument 4 is in R10 on the frame rather than RCX as RCX is used by @@ -359,7 +359,7 @@ FUNCTION(x86_64_syscall_entry): movq IFRAME_r8(%rbp), %r8 movq IFRAME_r9(%rbp), %r9 - // TODO: pre-syscall tracing/debug + // TODO: pre-syscall tracing // Call the function and save its return value. call *SYSCALL_INFO_function(%rax) @@ -367,7 +367,9 @@ FUNCTION(x86_64_syscall_entry): // TODO: post-syscall tracing -.Lbad_syscall_number: + // Restore the original stack pointer and return. + movq %rbp, %rsp + .Lsyscall_return: // Clear the restarted flag. testl $THREAD_FLAGS_SYSCALL_RESTARTED, THREAD_flags(%r12) @@ -405,9 +407,41 @@ FUNCTION(x86_64_syscall_entry): swapgs sysretq +.Lpre_syscall_debug: + // user_debug_pre_syscall expects a pointer to a block of arguments, need + // to push the register arguments onto the stack. + push IFRAME_r9(%rbp) + push IFRAME_r8(%rbp) + push IFRAME_r10(%rbp) + push IFRAME_dx(%rbp) + push IFRAME_si(%rbp) + push IFRAME_di(%rbp) + movq %r14, %rdi // syscall number + movq %rsp, %rsi + push %rax + call user_debug_pre_syscall + pop %rax + addq $48, %rsp + jmp .Lpre_syscall_debug_done + .Lpost_syscall_work: - // TODO: post-syscall debugging + testl $THREAD_FLAGS_DEBUGGER_INSTALLED, THREAD_flags(%r12) + jz 1f + // Post-syscall debugging. Same as above, need a block of arguments. + push IFRAME_r9(%rbp) + push IFRAME_r8(%rbp) + push IFRAME_r10(%rbp) + push IFRAME_dx(%rbp) + push IFRAME_si(%rbp) + push IFRAME_di(%rbp) + movq %r14, %rdi // syscall number + movq %rsp, %rsi + movq IFRAME_ax(%rbp), %rdx // return value + movq %r13, %rcx // start time, preserved earlier + call user_debug_post_syscall + addq $48, %rsp +1: // Do we need to handle signals? testl $(THREAD_FLAGS_SIGNALS_PENDING | THREAD_FLAGS_DEBUG_THREAD) \ , THREAD_flags(%r12) @@ -422,11 +456,11 @@ FUNCTION(x86_64_syscall_entry): movq %rsp, %rdi call x86_restart_syscall 1: - // Install breakpoints, if defined. TODO - //testl $THREAD_FLAGS_BREAKPOINTS_DEFINED, THREAD_flags(%r12) - //jz .Liret - //movq %rbp, %rdi - //call x86_init_user_debug_at_kernel_exit + // Install breakpoints, if defined. + testl $THREAD_FLAGS_BREAKPOINTS_DEFINED, THREAD_flags(%r12) + jz .Liret + movq %rbp, %rdi + call x86_init_user_debug_at_kernel_exit // On this return path it is possible that the frame has been modified, // for example to execute a signal handler. In this case it is safer to @@ -470,25 +504,8 @@ FUNCTION(x86_64_syscall_entry): movsq movq $0, THREAD_fault_handler(%r12) - // Restore the register arguments from the iframe. - movq IFRAME_di(%rbp), %rdi - movq IFRAME_si(%rbp), %rsi - movq IFRAME_dx(%rbp), %rdx - movq IFRAME_r10(%rbp), %rcx - movq IFRAME_r8(%rbp), %r8 - movq IFRAME_r9(%rbp), %r9 - - // TODO: pre-syscall tracing/debug - - // Call the function and save its return value. - call *SYSCALL_INFO_function(%rax) - movq %rax, IFRAME_ax(%rbp) - - // TODO: post-syscall tracing - - // Restore the original stack pointer and return. - movq %rbp, %rsp - jmp .Lsyscall_return + // Perform the call. + jmp .Lperform_syscall .Lbad_syscall_args: movq $0, THREAD_fault_handler(%r12) diff --git a/src/system/kernel/arch/x86/64/stubs.cpp b/src/system/kernel/arch/x86/64/stubs.cpp deleted file mode 100644 index 9ff4e71..0000000 --- a/src/system/kernel/arch/x86/64/stubs.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2012, Alex Smith, alex@xxxxxxxxxxxxxxxxx - * Distributed under the terms of the MIT License. - */ - - -// This file contains stubs for everything that's not been implemented yet on -// x86_64. - - -#include <cpu.h> -#include <commpage.h> -#include <debug.h> -#include <debugger.h> -#include <elf.h> -#include <elf_priv.h> -#include <real_time_clock.h> -#include <real_time_data.h> -#include <smp.h> -#include <timer.h> -#include <team.h> -#include <thread.h> -#include <vm/vm.h> -#include <vm/VMAddressSpace.h> - -#include <boot/kernel_args.h> - -#include <arch/debug.h> -#include <arch/vm_translation_map.h> -#include <arch/vm.h> -#include <arch/user_debugger.h> -#include <arch/timer.h> -#include <arch/thread.h> -#include <arch/system_info.h> -#include <arch/smp.h> -#include <arch/real_time_clock.h> -#include <arch/elf.h> - - -// The software breakpoint instruction (int3). -const uint8 kX86SoftwareBreakpoint[1] = { 0xcc }; - - -void -arch_clear_team_debug_info(struct arch_team_debug_info *info) -{ - -} - - -void -arch_destroy_team_debug_info(struct arch_team_debug_info *info) -{ - -} - - -void -arch_clear_thread_debug_info(struct arch_thread_debug_info *info) -{ - -} - - -void -arch_destroy_thread_debug_info(struct arch_thread_debug_info *info) -{ - -} - - -void -arch_update_thread_single_step() -{ - -} - - -void -arch_set_debug_cpu_state(const debug_cpu_state *cpuState) -{ - -} - - -void -arch_get_debug_cpu_state(debug_cpu_state *cpuState) -{ - -} - - -status_t -arch_set_breakpoint(void *address) -{ - return B_OK; -} - - -status_t -arch_clear_breakpoint(void *address) -{ - return B_OK; -} - - -status_t -arch_set_watchpoint(void *address, uint32 type, int32 length) -{ - return B_OK; -} - - -status_t -arch_clear_watchpoint(void *address) -{ - return B_OK; -} - - -bool -arch_has_breakpoints(struct arch_team_debug_info *info) -{ - return false; -} - - -void -x86_init_user_debug() -{ - -} - - -status_t -_user_read_kernel_image_symbols(image_id id, struct Elf32_Sym* symbolTable, - int32* _symbolCount, char* stringTable, size_t* _stringTableSize, - addr_t* _imageDelta) -{ - return B_ERROR; -} diff --git a/src/system/kernel/arch/x86/Jamfile b/src/system/kernel/arch/x86/Jamfile index 745f69b..beb468b 100644 --- a/src/system/kernel/arch/x86/Jamfile +++ b/src/system/kernel/arch/x86/Jamfile @@ -24,7 +24,6 @@ if $(TARGET_ARCH) = x86_64 { cpuid.S int.cpp interrupts.S - stubs.cpp signals.cpp signals_asm.S syscalls.cpp @@ -56,7 +55,6 @@ if $(TARGET_ARCH) = x86_64 { syscalls_asm.S thread.cpp - arch_user_debugger.cpp ioapic.cpp irq_routing_table.cpp @@ -88,6 +86,7 @@ local archGenericSources = arch_system_info.cpp arch_thread.cpp arch_timer.cpp + arch_user_debugger.cpp arch_vm.cpp arch_vm_translation_map.cpp apic.cpp diff --git a/src/system/kernel/arch/x86/arch_user_debugger.cpp b/src/system/kernel/arch/x86/arch_user_debugger.cpp index 4a5d232..3857c3d 100644 --- a/src/system/kernel/arch/x86/arch_user_debugger.cpp +++ b/src/system/kernel/arch/x86/arch_user_debugger.cpp @@ -39,27 +39,27 @@ extern bool gHasSSE; const uint8 kX86SoftwareBreakpoint[1] = { 0xcc }; // maps breakpoint slot index to LEN_i LSB number -static const uint32 sDR7Len[4] = { +static const size_t sDR7Len[4] = { X86_DR7_LEN0_LSB, X86_DR7_LEN1_LSB, X86_DR7_LEN2_LSB, X86_DR7_LEN3_LSB }; // maps breakpoint slot index to R/W_i LSB number -static const uint32 sDR7RW[4] = { +static const size_t sDR7RW[4] = { X86_DR7_RW0_LSB, X86_DR7_RW1_LSB, X86_DR7_RW2_LSB, X86_DR7_RW3_LSB }; // maps breakpoint slot index to L_i bit number -static const uint32 sDR7L[4] = { +static const size_t sDR7L[4] = { X86_DR7_L0, X86_DR7_L1, X86_DR7_L2, X86_DR7_L3 }; // maps breakpoint slot index to G_i bit number -static const uint32 sDR7G[4] = { +static const size_t sDR7G[4] = { X86_DR7_G0, X86_DR7_G1, X86_DR7_G2, X86_DR7_G3 }; // maps breakpoint slot index to B_i bit number -static const uint32 sDR6B[4] = { +static const size_t sDR6B[4] = { X86_DR6_B0, X86_DR6_B1, X86_DR6_B2, X86_DR6_B3 }; @@ -68,8 +68,78 @@ static const uint32 sDR6B[4] = { static bool sQEmuSingleStepHack = false; +#ifdef __x86_64__ + + +static void +get_iframe_registers(const iframe* frame, debug_cpu_state* cpuState) +{ + // Get general purpose registers. + cpuState->r15 = frame->r15; + cpuState->r14 = frame->r14; + cpuState->r13 = frame->r13; + cpuState->r12 = frame->r12; + cpuState->r11 = frame->r11; + cpuState->r10 = frame->r10; + cpuState->r9 = frame->r9; + cpuState->r8 = frame->r8; + cpuState->rbp = frame->bp; + cpuState->rsi = frame->si; + cpuState->rdi = frame->di; + cpuState->rdx = frame->dx; + cpuState->rcx = frame->cx; + cpuState->rbx = frame->bx; + cpuState->rax = frame->ax; + cpuState->rip = frame->ip; + cpuState->cs = frame->cs; + cpuState->rflags = frame->flags; + cpuState->rsp = frame->sp; + cpuState->ss = frame->ss; + + // Other segment registers are not saved or changed on interrupts, so + // get their value here. + uint16 seg; + __asm__ volatile ("movw %%ds, %0" : "=r" (seg)); + cpuState->ds = seg; + __asm__ volatile ("movw %%es, %0" : "=r" (seg)); + cpuState->es = seg; + __asm__ volatile ("movw %%fs, %0" : "=r" (seg)); + cpuState->fs = seg; + __asm__ volatile ("movw %%gs, %0" : "=r" (seg)); + cpuState->gs = seg; +} + + static void -get_iframe_registers(struct iframe *frame, debug_cpu_state *cpuState) +set_iframe_registers(iframe* frame, const debug_cpu_state* cpuState) +{ + frame->r15 = cpuState->r15; + frame->r14 = cpuState->r14; + frame->r13 = cpuState->r13; + frame->r12 = cpuState->r12; + frame->r11 = cpuState->r11; + frame->r10 = cpuState->r10; + frame->r9 = cpuState->r9; + frame->r8 = cpuState->r8; + frame->bp = cpuState->rbp; + frame->si = cpuState->rsi; + frame->di = cpuState->rdi; + frame->dx = cpuState->rdx; + frame->cx = cpuState->rcx; + frame->bx = cpuState->rbx; + frame->ax = cpuState->rax; + frame->ip = cpuState->rip; + frame->flags = (frame->flags & ~X86_EFLAGS_USER_SETTABLE_FLAGS) + | (cpuState->rflags & X86_EFLAGS_USER_SETTABLE_FLAGS); + frame->sp = cpuState->rsp; +} + + +#else // __x86_64__ + + +static void +get_iframe_registers(const iframe* frame, debug_cpu_state* cpuState) { cpuState->gs = frame->gs; cpuState->fs = frame->fs; @@ -93,25 +163,56 @@ get_iframe_registers(struct iframe *frame, debug_cpu_state *cpuState) } +static void +set_iframe_registers(iframe* frame, const debug_cpu_state* cpuState) +{ +// frame->gs = cpuState->gs; +// frame->fs = cpuState->fs; +// frame->es = cpuState->es; +// frame->ds = cpuState->ds; + frame->di = cpuState->edi; + frame->si = cpuState->esi; + frame->bp = cpuState->ebp; +// frame->esp = cpuState->esp; + frame->bx = cpuState->ebx; + frame->dx = cpuState->edx; + frame->cx = cpuState->ecx; + frame->ax = cpuState->eax; +// frame->vector = cpuState->vector; +// frame->error_code = cpuState->error_code; + frame->ip = cpuState->eip; +// frame->cs = cpuState->cs; + frame->flags = (frame->flags & ~X86_EFLAGS_USER_SETTABLE_FLAGS) + | (cpuState->eflags & X86_EFLAGS_USER_SETTABLE_FLAGS); + frame->user_sp = cpuState->user_esp; +// frame->user_ss = cpuState->user_ss; +} + + +#endif // __x86_64__ + + static inline void -install_breakpoints(const arch_team_debug_info &teamInfo) +install_breakpoints(const arch_team_debug_info& teamInfo) { // set breakpoints - asm("movl %0, %%dr0" : : "r"(teamInfo.breakpoints[0].address)); - asm("movl %0, %%dr1" : : "r"(teamInfo.breakpoints[1].address)); - asm("movl %0, %%dr2" : : "r"(teamInfo.breakpoints[2].address)); -// asm("movl %0, %%dr3" : : "r"(teamInfo.breakpoints[3].address)); - // DR3 is used to hold the current Thread*. + asm("mov %0, %%dr0" : : "r"(teamInfo.breakpoints[0].address)); + asm("mov %0, %%dr1" : : "r"(teamInfo.breakpoints[1].address)); + asm("mov %0, %%dr2" : : "r"(teamInfo.breakpoints[2].address)); +#ifdef __x86_64__ + asm("mov %0, %%dr3" : : "r"(teamInfo.breakpoints[3].address)); + // DR3 is used to hold the current Thread* on 32. +#endif // enable breakpoints - asm("movl %0, %%dr7" : : "r"(teamInfo.dr7)); + asm("mov %0, %%dr7" : : "r"(teamInfo.dr7)); } static inline void disable_breakpoints() { - asm("movl %0, %%dr7" : : "r"(X86_BREAKPOINTS_DISABLED_DR7)); + asm("mov %0, %%dr7" : : "r"((size_t)X86_BREAKPOINTS_DISABLED_DR7)); } @@ -119,8 +220,8 @@ disable_breakpoints() Interrupts must be disabled and the team debug info lock be held. */ static inline status_t -set_breakpoint(arch_team_debug_info &info, void *address, uint32 type, - uint32 length, bool setGlobalFlag) +set_breakpoint(arch_team_debug_info& info, void* address, size_t type, + size_t length, bool setGlobalFlag) { // check, if there is already a breakpoint at that address bool alreadySet = false; @@ -169,7 +270,7 @@ set_breakpoint(arch_team_debug_info &info, void *address, uint32 type, Interrupts must be disabled and the team debug info lock be held. */ static inline status_t -clear_breakpoint(arch_team_debug_info &info, void *address, bool watchpoint) +clear_breakpoint(arch_team_debug_info& info, void* address, bool watchpoint) { // find the breakpoint int32 slot = -1; @@ -202,12 +303,12 @@ clear_breakpoint(arch_team_debug_info &info, void *address, bool watchpoint) static status_t -set_breakpoint(void *address, uint32 type, uint32 length) +set_breakpoint(void* address, size_t type, size_t length) { if (!address) return B_BAD_VALUE; - Thread *thread = thread_get_current_thread(); + Thread* thread = thread_get_current_thread(); cpu_status state = disable_interrupts(); GRAB_TEAM_DEBUG_INFO_LOCK(thread->team->debug_info); @@ -223,12 +324,12 @@ set_breakpoint(void *address, uint32 type, uint32 length) static status_t -clear_breakpoint(void *address, bool watchpoint) +clear_breakpoint(void* address, bool watchpoint) { if (!address) return B_BAD_VALUE; - Thread *thread = thread_get_current_thread(); + Thread* thread = thread_get_current_thread(); cpu_status state = disable_interrupts(); GRAB_TEAM_DEBUG_INFO_LOCK(thread->team->debug_info); @@ -260,7 +361,7 @@ install_breakpoints_per_cpu(void* /*cookie*/, int cpu) static status_t -set_kernel_breakpoint(void *address, uint32 type, uint32 length) +set_kernel_breakpoint(void* address, size_t type, size_t length) { if (!address) return B_BAD_VALUE; @@ -284,7 +385,7 @@ set_kernel_breakpoint(void *address, uint32 type, uint32 length) static status_t -clear_kernel_breakpoint(void *address, bool watchpoint) +clear_kernel_breakpoint(void* address, bool watchpoint) { if (!address) return B_BAD_VALUE; @@ -311,7 +412,7 @@ clear_kernel_breakpoint(void *address, bool watchpoint) static inline status_t check_watch_point_parameters(void* address, uint32 type, int32 length, - uint32& archType, uint32& archLength) + size_t& archType, size_t& archLength) { // check type switch (type) { @@ -333,12 +434,12 @@ check_watch_point_parameters(void* address, uint32 type, int32 length, archLength = X86_BREAKPOINT_LENGTH_1; break; case 2: - if ((uint32)address & 0x1) + if ((addr_t)address & 0x1) return B_BAD_WATCHPOINT_ALIGNMENT; archLength = X86_BREAKPOINT_LENGTH_2; break; case 4: - if ((uint32)address & 0x3) + if ((addr_t)address & 0x3) return B_BAD_WATCHPOINT_ALIGNMENT; archLength = X86_BREAKPOINT_LENGTH_4; break; @@ -352,6 +453,7 @@ check_watch_point_parameters(void* address, uint32 type, int32 length, // #pragma mark - kernel debugger commands + #if KERNEL_BREAKPOINTS static int @@ -361,7 +463,7 @@ debugger_breakpoints(int argc, char** argv) arch_team_debug_info& info = kernelTeam->debug_info.arch_info; for (int32 i = 0; i < X86_BREAKPOINT_COUNT; i++) { - kprintf("breakpoint[%ld] ", i); + kprintf("breakpoint[%" B_PRId32 "] ", i); if (info.breakpoints[i].address != NULL) { kprintf("%p ", info.breakpoints[i].address); @@ -491,7 +593,7 @@ debugger_watchpoint(int argc, char** argv) uint32 type = readWrite ? B_DATA_READ_WRITE_WATCHPOINT : B_DATA_WRITE_WATCHPOINT; - uint32 archType, archLength; + size_t archType, archLength; error = check_watch_point_parameters((void*)address, type, length, archType, archLength); @@ -516,7 +618,7 @@ debugger_single_step(int argc, char** argv) // TODO: Since we need an iframe, this doesn't work when KDL wasn't entered // via an exception. - struct iframe* frame = x86_get_current_iframe(); + iframe* frame = x86_get_current_iframe(); if (frame == NULL) { kprintf("Failed to get the current iframe!\n"); return 0; @@ -535,7 +637,7 @@ debugger_single_step(int argc, char** argv) void -arch_clear_team_debug_info(struct arch_team_debug_info *info) +arch_clear_team_debug_info(arch_team_debug_info* info) { for (int32 i = 0; i < X86_BREAKPOINT_COUNT; i++) info->breakpoints[i].address = NULL; @@ -545,21 +647,21 @@ arch_clear_team_debug_info(struct arch_team_debug_info *info) void -arch_destroy_team_debug_info(struct arch_team_debug_info *info) +arch_destroy_team_debug_info(arch_team_debug_info* info) { arch_clear_team_debug_info(info); } void -arch_clear_thread_debug_info(struct arch_thread_debug_info *info) +arch_clear_thread_debug_info(arch_thread_debug_info* info) { info->flags = 0; } void -arch_destroy_thread_debug_info(struct arch_thread_debug_info *info) +arch_destroy_thread_debug_info(arch_thread_debug_info* info) { arch_clear_thread_debug_info(info); } @@ -568,7 +670,7 @@ arch_destroy_thread_debug_info(struct arch_thread_debug_info *info) void arch_update_thread_single_step() { - if (struct iframe* frame = x86_get_user_iframe()) { + if (iframe* frame = x86_get_user_iframe()) { Thread* thread = thread_get_current_thread(); // set/clear TF in EFLAGS depending on whether single stepping is @@ -582,9 +684,9 @@ arch_update_thread_single_step() void -arch_set_debug_cpu_state(const debug_cpu_state *cpuState) +arch_set_debug_cpu_state(const debug_cpu_state* cpuState) { - if (struct iframe *frame = x86_get_user_iframe()) { + if (iframe* frame = x86_get_user_iframe()) { // For the floating point state to be correct the calling function must // not use these registers (not even indirectly). if (gHasSSE) { @@ -597,39 +699,21 @@ arch_set_debug_cpu_state(const debug_cpu_state *cpuState) memcpy(thread->arch_info.fpu_state, &cpuState->extended_registers, sizeof(cpuState->extended_registers)); x86_fxrstor(thread->arch_info.fpu_state); +#ifndef __x86_64__ } else { // TODO: Implement! We need to convert the format first. // x86_frstor(&cpuState->extended_registers); +#endif } - -// frame->gs = cpuState->gs; -// frame->fs = cpuState->fs; -// frame->es = cpuState->es; -// frame->ds = cpuState->ds; - frame->di = cpuState->edi; - frame->si = cpuState->esi; - frame->bp = cpuState->ebp; -// frame->esp = cpuState->esp; - frame->bx = cpuState->ebx; - frame->dx = cpuState->edx; - frame->cx = cpuState->ecx; - frame->ax = cpuState->eax; -// frame->vector = cpuState->vector; -// frame->error_code = cpuState->error_code; - frame->ip = cpuState->eip; -// frame->cs = cpuState->cs; - frame->flags = (frame->flags & ~X86_EFLAGS_USER_SETTABLE_FLAGS) - | (cpuState->eflags & X86_EFLAGS_USER_SETTABLE_FLAGS); - frame->user_sp = cpuState->user_esp; -// frame->user_ss = cpuState->user_ss; + set_iframe_registers(frame, cpuState); } } void -arch_get_debug_cpu_state(debug_cpu_state *cpuState) +arch_get_debug_cpu_state(debug_cpu_state* cpuState) { - if (struct iframe *frame = x86_get_user_iframe()) { + if (iframe* frame = x86_get_user_iframe()) { // For the floating point state to be correct the calling function must // not use these registers (not even indirectly). if (gHasSSE) { @@ -642,12 +726,14 @@ arch_get_debug_cpu_state(debug_cpu_state *cpuState) // unlike fnsave, fxsave doesn't reinit the FPU state memcpy(&cpuState->extended_registers, thread->arch_info.fpu_state, sizeof(cpuState->extended_registers)); +#ifndef __x86_64__ } else { x86_fnsave(&cpuState->extended_registers); x86_frstor(&cpuState->extended_registers); // fnsave reinits the FPU state after saving, so we need to // load it again // TODO: Convert to fxsave format! +#endif } get_iframe_registers(frame, cpuState); } @@ -655,7 +741,7 @@ arch_get_debug_cpu_state(debug_cpu_state *cpuState) status_t -arch_set_breakpoint(void *address) +arch_set_breakpoint(void* address) { return set_breakpoint(address, X86_INSTRUCTION_BREAKPOINT, X86_BREAKPOINT_LENGTH_1); @@ -663,16 +749,16 @@ arch_set_breakpoint(void *address) status_t -arch_clear_breakpoint(void *address) +arch_clear_breakpoint(void* address) { return clear_breakpoint(address, false); } status_t -arch_set_watchpoint(void *address, uint32 type, int32 length) +arch_set_watchpoint(void* address, uint32 type, int32 length) { - uint32 archType, archLength; + size_t archType, archLength; status_t error = check_watch_point_parameters(address, type, length, archType, archLength); if (error != B_OK) @@ -683,14 +769,14 @@ arch_set_watchpoint(void *address, uint32 type, int32 length) status_t -arch_clear_watchpoint(void *address) +arch_clear_watchpoint(void* address) { return clear_breakpoint(address, true); } bool -arch_has_breakpoints(struct arch_team_debug_info *info) +arch_has_breakpoints(arch_team_debug_info* info) { // Reading info->dr7 is atomically, so we don't need to lock. The caller // has to ensure, that the info doesn't go away. @@ -701,7 +787,7 @@ arch_has_breakpoints(struct arch_team_debug_info *info) #if KERNEL_BREAKPOINTS status_t -arch_set_kernel_breakpoint(void *address) +arch_set_kernel_breakpoint(void* address) { status_t error = set_kernel_breakpoint(address, X86_INSTRUCTION_BREAKPOINT, X86_BREAKPOINT_LENGTH_1); @@ -716,7 +802,7 @@ arch_set_kernel_breakpoint(void *address) status_t -arch_clear_kernel_breakpoint(void *address) +arch_clear_kernel_breakpoint(void* address) { status_t error = clear_kernel_breakpoint(address, false); @@ -730,9 +816,9 @@ arch_clear_kernel_breakpoint(void *address) status_t -arch_set_kernel_watchpoint(void *address, uint32 type, int32 length) +arch_set_kernel_watchpoint(void* address, uint32 type, int32 length) { - uint32 archType, archLength; + size_t archType, archLength; status_t error = check_watch_point_parameters(address, type, length, archType, archLength); @@ -749,7 +835,7 @@ arch_set_kernel_watchpoint(void *address, uint32 type, int32 length) status_t -arch_clear_kernel_watchpoint(void *address) +arch_clear_kernel_watchpoint(void* address) { status_t error = clear_kernel_breakpoint(address, true); @@ -771,9 +857,9 @@ arch_clear_kernel_watchpoint(void *address) * Interrupts are disabled. \a frame is unused, i.e. can be \c NULL. */ void -x86_init_user_debug_at_kernel_exit(struct iframe *frame) +x86_init_user_debug_at_kernel_exit(iframe* frame) { - Thread *thread = thread_get_current_thread(); + Thread* thread = thread_get_current_thread(); if (!(thread->flags & THREAD_FLAGS_BREAKPOINTS_DEFINED)) return; @@ -800,14 +886,14 @@ x86_init_user_debug_at_kernel_exit(struct iframe *frame) void x86_exit_user_debug_at_kernel_entry() { - Thread *thread = thread_get_current_thread(); + Thread* thread = thread_get_current_thread(); // We need to save the current values of dr6 and dr7 in the CPU structure, // since in case of a debug exception we might overwrite them before // x86_handle_debug_exception() is called. Debug exceptions occur when // hitting a hardware break/watchpoint or when single-stepping. - asm("movl %%dr6, %0" : "=r"(thread->cpu->arch.dr6)); - asm("movl %%dr7, %0" : "=r"(thread->cpu->arch.dr7)); + asm("mov %%dr6, %0" : "=r"(thread->cpu->arch.dr6)); + asm("mov %%dr7, %0" : "=r"(thread->cpu->arch.dr7)); // The remainder needs only be done, when user breakpoints are installed. if (!(thread->flags & THREAD_FLAGS_BREAKPOINTS_INSTALLED)) @@ -833,7 +919,7 @@ x86_exit_user_debug_at_kernel_entry() * Interrupts are disabled and will possibly be enabled by the function. */ void -x86_handle_debug_exception(struct iframe *frame) +x86_handle_debug_exception(iframe* frame) { Thread* thread = thread_get_current_thread(); @@ -842,14 +928,14 @@ x86_handle_debug_exception(struct iframe *frame) // x86_exit_user_debug_at_kernel_entry() has already been invoked and dr6 // and dr7 are stored in the cpu info. Otherwise we need to fetch the // current values from the registers. - uint32 dr6; - uint32 dr7; + size_t dr6; + size_t dr7; if (IFRAME_IS_USER(frame)) { dr6 = thread->cpu->arch.dr6; dr7 = thread->cpu->arch.dr7; } else { - asm("movl %%dr6, %0" : "=r"(dr6)); - asm("movl %%dr7, %0" : "=r"(dr7)); + asm("mov %%dr6, %0" : "=r"(dr6)); + asm("mov %%dr7, %0" : "=r"(dr7)); } TRACE(("x86_handle_debug_exception(): DR6: %lx, DR7: %lx\n", dr6, dr7)); @@ -862,7 +948,7 @@ x86_handle_debug_exception(struct iframe *frame) bool watchpoint = true; for (int32 i = 0; i < X86_BREAKPOINT_COUNT; i++) { if (dr6 & (1 << sDR6B[i])) { - uint32 type = (dr7 >> sDR7RW[i]) & 0x3; + size_t type = (dr7 >> sDR7RW[i]) & 0x3; if (type == X86_INSTRUCTION_BREAKPOINT) watchpoint = false; } @@ -972,7 +1058,7 @@ x86_handle_debug_exception(struct iframe *frame) * Interrupts are disabled and will possibly be enabled by the function. */ void -x86_handle_breakpoint_exception(struct iframe *frame) +x86_handle_breakpoint_exception(iframe* frame) { TRACE(("x86_handle_breakpoint_exception()\n")); @@ -994,7 +1080,7 @@ void x86_init_user_debug() { // get debug settings - if (void *handle = load_driver_settings("kernel")) { + if (void* handle = load_driver_settings("kernel")) { sQEmuSingleStepHack = get_driver_boolean_parameter(handle, "qemu_single_step_hack", false, false);; diff --git a/src/system/kernel/debug/user_debugger.cpp b/src/system/kernel/debug/user_debugger.cpp index 12d355b..a3f1915 100644 --- a/src/system/kernel/debug/user_debugger.cpp +++ b/src/system/kernel/debug/user_debugger.cpp @@ -77,8 +77,9 @@ static status_t debugger_write(port_id port, int32 code, const void *buffer, size_t bufferSize, bool dontWait) { - TRACE(("debugger_write(): thread: %ld, team %ld, port: %ld, code: %lx, message: %p, " - "size: %lu, dontWait: %d\n", thread_get_current_thread()->id, + TRACE(("debugger_write(): thread: %" B_PRId32 ", team %" B_PRId32 ", " + "port: %" B_PRId32 ", code: %" B_PRIx32 ", message: %p, size: %lu, " + "dontWait: %d\n", thread_get_current_thread()->id, thread_get_current_thread()->team->id, port, code, buffer, bufferSize, dontWait)); @@ -94,7 +95,7 @@ debugger_write(port_id port, int32 code, const void *buffer, size_t bufferSize, error = acquire_sem_etc(writeLock, 1, dontWait ? (uint32)B_RELATIVE_TIMEOUT : (uint32)B_KILL_CAN_INTERRUPT, 0); if (error != B_OK) { - TRACE(("debugger_write() done1: %lx\n", error)); + TRACE(("debugger_write() done1: %" B_PRIx32 "\n", error)); return error; } @@ -119,7 +120,7 @@ debugger_write(port_id port, int32 code, const void *buffer, size_t bufferSize, // release the write lock release_sem(writeLock); - TRACE(("debugger_write() done: %lx\n", error)); + TRACE(("debugger_write() done: %" B_PRIx32 "\n", error)); return error; } @@ -529,8 +530,9 @@ thread_hit_debug_event_internal(debug_debugger_message event, restart = false; Thread *thread = thread_get_current_thread(); - TRACE(("thread_hit_debug_event(): thread: %ld, event: %lu, message: %p, " - "size: %ld\n", thread->id, (uint32)event, message, size)); + TRACE(("thread_hit_debug_event(): thread: %" B_PRId32 ", event: %" B_PRIu32 + ", message: %p, size: %" B_PRId32 "\n", thread->id, (uint32)event, + message, size)); // check, if there's a debug port already bool setPort = !(atomic_get(&thread->debug_info.flags) @@ -567,8 +569,8 @@ thread_hit_debug_event_internal(debug_debugger_message event, = (thread->team->debug_info.flags & B_TEAM_DEBUG_DEBUGGER_INSTALLED); if (thread->id == thread->team->debug_info.nub_thread) { // Ugh, we're the nub thread. We shouldn't be here. - TRACE(("thread_hit_debug_event(): Misdirected nub thread: %ld\n", - thread->id)); + TRACE(("thread_hit_debug_event(): Misdirected nub thread: %" B_PRId32 + "\n", thread->id)); error = B_ERROR; } else if (debuggerInstalled || !requireDebugger) { @@ -614,8 +616,8 @@ thread_hit_debug_event_internal(debug_debugger_message event, delete_port(deletePort); if (error != B_OK) { - TRACE(("thread_hit_debug_event() error: thread: %ld, error: %lx\n", - thread->id, error)); + TRACE(("thread_hit_debug_event() error: thread: %" B_PRId32 ", error: " + "%" B_PRIx32 "\n", thread->id, error)); return error; } @@ -627,8 +629,9 @@ thread_hit_debug_event_internal(debug_debugger_message event, origin->team = thread->team->id; origin->nub_port = nubPort; - TRACE(("thread_hit_debug_event(): thread: %ld, sending message to " - "debugger port %ld\n", thread->id, debuggerPort)); + TRACE(("thread_hit_debug_event(): thread: %" B_PRId32 ", sending " + "message to debugger port %" B_PRId32 "\n", thread->id, + debuggerPort)); error = debugger_write(debuggerPort, event, message, size, false); } @@ -648,15 +651,15 @@ thread_hit_debug_event_internal(debug_debugger_message event, if (commandMessageSize < 0) { error = commandMessageSize; - TRACE(("thread_hit_debug_event(): thread: %ld, failed " - "to receive message from port %ld: %lx\n", + TRACE(("thread_hit_debug_event(): thread: %" B_PRId32 ", failed " + "to receive message from port %" B_PRId32 ": %" B_PRIx32 "\n", thread->id, port, error)); break; } switch (command) { case B_DEBUGGED_THREAD_MESSAGE_CONTINUE: - TRACE(("thread_hit_debug_event(): thread: %ld: " + TRACE(("thread_hit_debug_event(): thread: %" B_PRId32 ": " "B_DEBUGGED_THREAD_MESSAGE_CONTINUE\n", thread->id)); result = commandMessage.continue_thread.handle_event; @@ -667,7 +670,7 @@ thread_hit_debug_event_internal(debug_debugger_message event, case B_DEBUGGED_THREAD_SET_CPU_STATE: { - TRACE(("thread_hit_debug_event(): thread: %ld: " + TRACE(("thread_hit_debug_event(): thread: %" B_PRId32 ": " "B_DEBUGGED_THREAD_SET_CPU_STATE\n", thread->id)); arch_set_debug_cpu_state( @@ -720,9 +723,9 @@ thread_hit_debug_event_internal(debug_debugger_message event, } } } else { - TRACE(("thread_hit_debug_event(): thread: %ld, failed to send " - "message to debugger port %ld: %lx\n", thread->id, - debuggerPort, error)); + TRACE(("thread_hit_debug_event(): thread: %" B_PRId32 ", failed to send " + "message to debugger port %" B_PRId32 ": %" B_PRIx32 "\n", + thread->id, debuggerPort, error)); } // update the thread debug info @@ -993,8 +996,8 @@ void user_debug_team_deleted(team_id teamID, port_id debuggerPort) { if (debuggerPort >= 0) { - TRACE(("user_debug_team_deleted(team: %ld, debugger port: %ld)\n", - teamID, debuggerPort)); + TRACE(("user_debug_team_deleted(team: %" B_PRId32 ", debugger port: " + "%" B_PRId32 ")\n", teamID, debuggerPort)); debug_team_deleted message; message.origin.thread = -1; @@ -1541,7 +1544,8 @@ broadcast_debugged_thread_message(Thread *nubThread, int32 code, code, message, size); if (error != B_OK) { TRACE(("broadcast_debugged_thread_message(): Failed to send " - "message to thread %ld: %lx\n", thread->id, error)); + "message to thread %" B_PRId32 ": %" B_PRIx32 "\n", + thread->id, error)); } } } @@ -1551,8 +1555,8 @@ broadcast_debugged_thread_message(Thread *nubThread, int32 code, static void nub_thread_cleanup(Thread *nubThread) { - TRACE(("nub_thread_cleanup(%ld): debugger port: %ld\n", nubThread->id, - nubThread->team->debug_info.debugger_port)); + TRACE(("nub_thread_cleanup(%" B_PRId32 "): debugger port: %" B_PRId32 "\n", + nubThread->id, nubThread->team->debug_info.debugger_port)); ConditionVariable debugChangeCondition; prepare_debugger_change(nubThread->team, debugChangeCondition); @@ -1654,8 +1658,8 @@ debug_nub_thread(void *) RELEASE_TEAM_DEBUG_INFO_LOCK(nubThread->team->debug_info); restore_interrupts(state); - TRACE(("debug_nub_thread() thread: %ld, team %ld, nub port: %ld\n", - nubThread->id, nubThread->team->id, port)); + TRACE(("debug_nub_thread() thread: %" B_PRId32 ", team %" B_PRId32 ", nub " + "port: %" B_PRId32 "\n", nubThread->id, nubThread->team->id, port)); // notify all threads that a debugger has been installed broadcast_debugged_thread_message(nubThread, @@ -1674,8 +1678,8 @@ debug_nub_thread(void *) // thread, we need to update that. nub_thread_cleanup(nubThread); - TRACE(("nub thread %ld: terminating: %lx\n", nubThread->id, - messageSize)); + TRACE(("nub thread %" B_PRId32 ": terminating: %lx\n", + nubThread->id, messageSize)); return messageSize; } @@ -1719,10 +1723,10 @@ debug_nub_thread(void *) } reply.read_memory.error = result; - TRACE(("nub thread %ld: B_DEBUG_MESSAGE_READ_MEMORY: " - "reply port: %ld, address: %p, size: %ld, result: %lx, " - "read: %ld\n", nubThread->id, replyPort, address, size, - result, bytesRead)); + TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_READ_MEMORY: " + "reply port: %" B_PRId32 ", address: %p, size: %" B_PRId32 + ", result: %" B_PRIx32 ", read: %ld\n", nubThread->id, + replyPort, address, size, result, bytesRead)); // send only as much data as necessary reply.read_memory.size = bytesRead; @@ -1755,10 +1759,10 @@ debug_nub_thread(void *) } reply.write_memory.error = result; - TRACE(("nub thread %ld: B_DEBUG_MESSAGE_WRITE_MEMORY: " - "reply port: %ld, address: %p, size: %ld, result: %lx, " - "written: %ld\n", nubThread->id, replyPort, address, size, - result, bytesWritten)); + TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_WRITE_MEMORY: " + "reply port: %" B_PRId32 ", address: %p, size: %" B_PRId32 + ", result: %" B_PRIx32 ", written: %ld\n", nubThread->id, + replyPort, address, size, result, bytesWritten)); reply.write_memory.size = bytesWritten; sendReply = true; @@ -1772,8 +1776,8 @@ debug_nub_thread(void *) int32 flags = message.set_team_flags.flags & B_TEAM_DEBUG_USER_FLAG_MASK; - TRACE(("nub thread %ld: B_DEBUG_MESSAGE_SET_TEAM_FLAGS: " - "flags: %lx\n", nubThread->id, flags)); + TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_SET_TEAM_FLAGS" + ": flags: %" B_PRIx32 "\n", nubThread->id, flags)); Team *team = thread_get_current_thread()->team; @@ -1797,9 +1801,9 @@ debug_nub_thread(void *) int32 flags = message.set_thread_flags.flags & B_THREAD_DEBUG_USER_FLAG_MASK; - TRACE(("nub thread %ld: B_DEBUG_MESSAGE_SET_THREAD_FLAGS: " - "thread: %ld, flags: %lx\n", nubThread->id, threadID, - flags)); + TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_SET_THREAD_FLAGS" + ": thread: %" B_PRId32 ", flags: %" B_PRIx32 "\n", + nubThread->id, threadID, flags)); // set the flags Thread* thread = Thread::GetAndLock(threadID); @@ -1831,9 +1835,10 @@ debug_nub_thread(void *) handleEvent = message.continue_thread.handle_event; singleStep = message.continue_thread.single_step; - TRACE(("nub thread %ld: B_DEBUG_MESSAGE_CONTINUE_THREAD: " - "thread: %ld, handle event: %lu, single step: %d\n", - nubThread->id, threadID, handleEvent, singleStep)); + TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_CONTINUE_THREAD" + ": thread: %" B_PRId32 ", handle event: %" B_PRIu32 ", " + "single step: %d\n", nubThread->id, threadID, handleEvent, + singleStep)); // find the thread and get its debug port port_id threadDebugPort = -1; @@ -1861,8 +1866,8 @@ debug_nub_thread(void *) const debug_cpu_state &cpuState = message.set_cpu_state.cpu_state; - TRACE(("nub thread %ld: B_DEBUG_MESSAGE_SET_CPU_STATE: " - "thread: %ld\n", nubThread->id, threadID)); + TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_SET_CPU_STATE" + ": thread: %" B_PRId32 "\n", nubThread->id, threadID)); // find the thread and get its debug port port_id threadDebugPort = -1; @@ -1888,8 +1893,8 @@ debug_nub_thread(void *) thread_id threadID = message.get_cpu_state.thread; replyPort = message.get_cpu_state.reply_port; - TRACE(("nub thread %ld: B_DEBUG_MESSAGE_GET_CPU_STATE: " - "thread: %ld\n", nubThread->id, threadID)); + TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_GET_CPU_STATE" + ": thread: %" B_PRId32 "\n", nubThread->id, threadID)); // find the thread and get its debug port port_id threadDebugPort = -1; @@ -1921,8 +1926,8 @@ debug_nub_thread(void *) replyPort = message.set_breakpoint.reply_port; void *address = message.set_breakpoint.address; - TRACE(("nub thread %ld: B_DEBUG_MESSAGE_SET_BREAKPOINT: " - "address: %p\n", nubThread->id, address)); + TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_SET_BREAKPOINT" + ": address: %p\n", nubThread->id, address)); // check the address status_t result = B_OK; @@ -1951,8 +1956,8 @@ debug_nub_thread(void *) // get the parameters void *address = message.clear_breakpoint.address; - TRACE(("nub thread %ld: B_DEBUG_MESSAGE_CLEAR_BREAKPOINT: " - "address: %p\n", nubThread->id, address)); + TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_CLEAR_BREAKPOINT" + ": address: %p\n", nubThread->id, address)); // check the address status_t result = B_OK; @@ -1979,9 +1984,9 @@ debug_nub_thread(void *) uint32 type = message.set_watchpoint.type; int32 length = message.set_watchpoint.length; - TRACE(("nub thread %ld: B_DEBUG_MESSAGE_SET_WATCHPOINT: " - "address: %p, type: %lu, length: %ld\n", nubThread->id, - address, type, length)); + TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_SET_WATCHPOINT" + ": address: %p, type: %" B_PRIu32 ", length: %" B_PRId32 "\n", + nubThread->id, address, type, length)); // check the address and size status_t result = B_OK; @@ -2014,8 +2019,8 @@ debug_nub_thread(void *) // get the parameters void *address = message.clear_watchpoint.address; - TRACE(("nub thread %ld: B_DEBUG_MESSAGE_CLEAR_WATCHPOINT: " - "address: %p\n", nubThread->id, address)); + TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_CLEAR_WATCHPOINT" + ": address: %p\n", nubThread->id, address)); // check the address status_t result = B_OK; @@ -2043,10 +2048,11 @@ debug_nub_thread(void *) uint32 ignoreOp = message.set_signal_masks.ignore_op; uint32 ignoreOnceOp = message.set_signal_masks.ignore_once_op; - TRACE(("nub thread %ld: B_DEBUG_MESSAGE_SET_SIGNAL_MASKS: " - "thread: %ld, ignore: %llx (op: %lu), ignore once: %llx " - "(op: %lu)\n", nubThread->id, threadID, ignore, - ignoreOp, ignoreOnce, ignoreOnceOp)); + TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_SET_SIGNAL_MASKS" + ": thread: %" B_PRId32 ", ignore: %" B_PRIx64 " (op: %" + B_PRIu32 "), ignore once: %" B_PRIx64 " (op: %" B_PRIu32 + ")\n", nubThread->id, threadID, ignore, ignoreOp, + ignoreOnce, ignoreOnceOp)); // set the masks Thread* thread = Thread::GetAndLock(threadID); @@ -2114,10 +2120,11 @@ debug_nub_thread(void *) } else result = B_BAD_THREAD_ID; - TRACE(("nub thread %ld: B_DEBUG_MESSAGE_GET_SIGNAL_MASKS: " - "reply port: %ld, thread: %ld, ignore: %llx, " - "ignore once: %llx, result: %lx\n", nubThread->id, - replyPort, threadID, ignore, ignoreOnce, result)); + TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_GET_SIGNAL_MASKS" + ": reply port: %" B_PRId32 ", thread: %" B_PRId32 ", " + "ignore: %" B_PRIx64 ", ignore once: %" B_PRIx64 ", result: " + "%" B_PRIx32 "\n", nubThread->id, replyPort, threadID, + ignore, ignoreOnce, result)); // prepare the message reply.get_signal_masks.error = result; @@ -2134,9 +2141,9 @@ debug_nub_thread(void *) int signal = message.set_signal_handler.signal; struct sigaction &handler = message.set_signal_handler.handler; - TRACE(("nub thread %ld: B_DEBUG_MESSAGE_SET_SIGNAL_HANDLER: " - "signal: %d, handler: %p\n", nubThread->id, - signal, handler.sa_handler)); + TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_SET_SIGNAL_HANDLER" + ": signal: %d, handler: %p\n", nubThread->id, signal, + handler.sa_handler)); // set the handler sigaction(signal, &handler, NULL); @@ -2157,9 +2164,9 @@ debug_nub_thread(void *) result = errno; } - TRACE(("nub thread %ld: B_DEBUG_MESSAGE_GET_SIGNAL_HANDLER: " - "reply port: %ld, signal: %d, handler: %p\n", nubThread->id, - replyPort, signal, + TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_GET_SIGNAL_HANDLER" + ": reply port: %" B_PRId32 ", signal: %d, handler: %p\n", + nubThread->id, replyPort, signal, reply.get_signal_handler.handler.sa_handler)); // prepare the message @@ -2171,8 +2178,8 @@ debug_nub_thread(void *) case B_DEBUG_MESSAGE_PREPARE_HANDOVER: { - TRACE(("nub thread %ld: B_DEBUG_MESSAGE_PREPARE_HANDOVER\n", - nubThread->id)); + TRACE(("nub thread %" B_PRId32 ": B_DEBUG_MESSAGE_PREPARE_HANDOVER" + "\n", nubThread->id)); Team *team = nubThread->team; @@ -2228,9 +2235,9 @@ debug_nub_thread(void *) B_DEBUG_MIN_PROFILE_INTERVAL); status_t result = B_OK; - TRACE(("nub thread %ld: B_DEBUG_START_PROFILER: " - "thread: %ld, sample area: %ld\n", nubThread->id, threadID, - sampleArea)); + TRACE(("nub thread %" B_PRId32 ": B_DEBUG_START_PROFILER: " + "thread: %" B_PRId32 ", sample area: %" B_PRId32 "\n", + nubThread->id, threadID, sampleArea)); if (stackDepth < 1) stackDepth = 1; @@ -2331,8 +2338,8 @@ debug_nub_thread(void *) replyPort = message.stop_profiler.reply_port; status_t result = B_OK; - TRACE(("nub thread %ld: B_DEBUG_STOP_PROFILER: " - "thread: %ld\n", nubThread->id, threadID)); + TRACE(("nub thread %" B_PRId32 ": B_DEBUG_STOP_PROFILER: " + "thread: %" B_PRId32 "\n", nubThread->id, threadID)); area_id sampleArea = -1; addr_t* samples = NULL; @@ -2407,8 +2414,9 @@ debug_nub_thread(void *) if (error != B_OK) { // The debugger port is either not longer existing or we got // interrupted by a kill signal. In either case we terminate. - TRACE(("nub thread %ld: failed to send reply to port %ld: %s\n", - nubThread->id, replyPort, strerror(error))); + TRACE(("nub thread %" B_PRId32 ": failed to send reply to port " + "%" B_PRId32 ": %s\n", nubThread->id, replyPort, + strerror(error))); nub_thread_cleanup(nubThread); return error; @@ -2470,8 +2478,9 @@ static port_id install_team_debugger(team_id teamID, port_id debuggerPort, thread_id causingThread, bool useDefault, bool dontReplace) { - TRACE(("install_team_debugger(team: %ld, port: %ld, default: %d, " - "dontReplace: %d)\n", teamID, debuggerPort, useDefault, dontReplace)); + TRACE(("install_team_debugger(team: %" B_PRId32 ", port: %" B_PRId32 ", " + "default: %d, dontReplace: %d)\n", teamID, debuggerPort, useDefault, + dontReplace)); if (useDefault) debuggerPort = atomic_get(&sDefaultDebuggerPort); @@ -2481,7 +2490,7 @@ install_team_debugger(team_id teamID, port_id debuggerPort, status_t error = get_port_info(debuggerPort, &debuggerPortInfo); if (error != B_OK) { TRACE(("install_team_debugger(): Failed to get debugger port info: " - "%lx\n", error)); + "%" B_PRIx32 "\n", error)); return error; } team_id debuggerTeam = debuggerPortInfo.team; @@ -2490,7 +2499,8 @@ install_team_debugger(team_id teamID, port_id debuggerPort, // debugged team. if (debuggerTeam == team_get_kernel_team_id() || debuggerTeam == teamID) { TRACE(("install_team_debugger(): Can't debug kernel or debugger team. " - "debugger: %ld, debugged: %ld\n", debuggerTeam, teamID)); + "debugger: %" B_PRId32 ", debugged: %" B_PRId32 "\n", debuggerTeam, + teamID)); return B_NOT_ALLOWED; } @@ -2618,13 +2628,14 @@ install_team_debugger(team_id teamID, port_id debuggerPort, } TRACE(("install_team_debugger() done: handed over to debugger: team: " - "%ld, port: %ld\n", debuggerTeam, debuggerPort)); + "%" B_PRId32 ", port: %" B_PRId32 "\n", debuggerTeam, + debuggerPort)); return result; } if (done || error != B_OK) { - TRACE(("install_team_debugger() done1: %ld\n", + TRACE(("install_team_debugger() done1: %" B_PRId32 "\n", (error == B_OK ? result : error))); finish_debugger_change(team); return (error == B_OK ? result : error); @@ -2708,7 +2719,7 @@ install_team_debugger(team_id teamID, port_id debuggerPort, delete breakpointManager; } - TRACE(("install_team_debugger() done2: %ld\n", + TRACE(("install_team_debugger() done2: %" B_PRId32 "\n", (error == B_OK ? result : error))); return (error == B_OK ? result : error); } @@ -2759,7 +2770,8 @@ _user_disable_debugger(int state) { Team *team = thread_get_current_thread()->team; - TRACE(("_user_disable_debugger(%d): team: %ld\n", state, team->id)); + TRACE(("_user_disable_debugger(%d): team: %" B_PRId32 "\n", state, + team->id)); cpu_status cpuState = disable_interrupts(); GRAB_TEAM_DEBUG_INFO_LOCK(team->debug_info); @@ -2853,7 +2865,8 @@ _user_remove_team_debugger(team_id teamID) status_t _user_debug_thread(thread_id threadID) { - TRACE(("[%ld] _user_debug_thread(%ld)\n", find_thread(NULL), threadID)); + TRACE(("[%" B_PRId32 "] _user_debug_thread(%" B_PRId32 ")\n", + find_thread(NULL), threadID)); // get the thread Thread* thread = Thread::GetAndLock(threadID); diff --git a/src/system/kernel/elf.cpp b/src/system/kernel/elf.cpp index 2c068fc..19d5e55 100644 --- a/src/system/kernel/elf.cpp +++ b/src/system/kernel/elf.cpp @@ -2506,8 +2506,6 @@ elf_init(kernel_args *args) // #pragma mark - -// TODO: x86_64 -#ifndef __x86_64__ /*! Reads the symbol and string table for the kernel image with the given ID. \a _symbolCount and \a _stringTableSize are both in- and output parameters. When called they call the size of the buffers given by \a symbolTable and @@ -2519,7 +2517,7 @@ elf_init(kernel_args *args) values in the table to get the actual symbol addresses. */ status_t -_user_read_kernel_image_symbols(image_id id, struct Elf32_Sym* symbolTable, +_user_read_kernel_image_symbols(image_id id, elf_sym* symbolTable, int32* _symbolCount, char* stringTable, size_t* _stringTableSize, addr_t* _imageDelta) { @@ -2551,7 +2549,7 @@ _user_read_kernel_image_symbols(image_id id, struct Elf32_Sym* symbolTable, // get the tables and infos addr_t imageDelta = image->text_region.delta; - const Elf32_Sym* symbols; + const elf_sym* symbols; int32 symbolCount; const char* strings; @@ -2579,7 +2577,7 @@ _user_read_kernel_image_symbols(image_id id, struct Elf32_Sym* symbolTable, // copy symbol table int32 symbolsToCopy = min_c(symbolCount, maxSymbolCount); if (symbolTable != NULL && symbolsToCopy > 0) { - if (user_memcpy(symbolTable, symbols, sizeof(Elf32_Sym) * symbolsToCopy) + if (user_memcpy(symbolTable, symbols, sizeof(elf_sym) * symbolsToCopy) != B_OK) { return B_BAD_ADDRESS; } @@ -2605,4 +2603,3 @@ _user_read_kernel_image_symbols(image_id id, struct Elf32_Sym* symbolTable, return B_OK; } -#endif ############################################################################ Commit: a731ad19e680a5ec387be3e4345445cadcd75fb4 Author: Alex Smith <alex@xxxxxxxxxxxxxxxx> Date: Tue Aug 7 19:22:36 2012 UTC ELF64 and x86_64 support in the debug kit. ---------------------------------------------------------------------------- diff --git a/src/kits/debug/DebugEventStream.cpp b/src/kits/debug/DebugEventStream.cpp index 422efe3..ec2711e 100644 --- a/src/kits/debug/DebugEventStream.cpp +++ b/src/kits/debug/DebugEventStream.cpp @@ -123,7 +123,7 @@ BDebugEventInputStream::Seek(off_t streamOffset) if (fStream != NULL) return B_UNSUPPORTED; - if (streamOffset < 0 || streamOffset > fBufferCapacity) + if (streamOffset < 0 || streamOffset > (off_t)fBufferCapacity) return B_BUFFER_OVERFLOW; fStreamPosition = 0; diff --git a/src/kits/debug/Image.cpp b/src/kits/debug/Image.cpp index 4075b48..170122e 100644 --- a/src/kits/debug/Image.cpp +++ b/src/kits/debug/Image.cpp @@ -82,17 +82,17 @@ SymbolTableBasedImage::~SymbolTableBasedImage() } -const Elf32_Sym* +const elf_sym* SymbolTableBasedImage::LookupSymbol(addr_t address, addr_t* _baseAddress, const char** _symbolName, size_t *_symbolNameLen, bool *_exactMatch) const { - const Elf32_Sym* symbolFound = NULL; + const elf_sym* symbolFound = NULL; const char* symbolName = NULL; bool exactMatch = false; addr_t deltaFound = ~(addr_t)0; for (int32 i = 0; i < fSymbolCount; i++) { - const Elf32_Sym* symbol = &fSymbolTable[i]; + const elf_sym* symbol = &fSymbolTable[i]; if (symbol->st_value == 0 || symbol->st_size >= (size_t)fInfo.text_size + fInfo.data_size) { @@ -141,10 +141,9 @@ SymbolTableBasedImage::NextSymbol(int32& iterator, const char** _symbolName, if (++iterator >= fSymbolCount) return B_ENTRY_NOT_FOUND; - const Elf32_Sym* symbol = &fSymbolTable[iterator]; + const elf_sym* symbol = &fSymbolTable[iterator]; - if ((ELF32_ST_TYPE(symbol->st_info) != STT_FUNC - && ELF32_ST_TYPE(symbol->st_info) != STT_OBJECT) + if ((symbol->Type() != STT_FUNC && symbol->Type() != STT_OBJECT) || symbol->st_value == 0) { continue; } @@ -153,8 +152,8 @@ SymbolTableBasedImage::NextSymbol(int32& iterator, const char** _symbolName, *_symbolNameLen = _SymbolNameLen(*_symbolName); *_symbolAddress = symbol->st_value + fLoadDelta; *_symbolSize = symbol->st_size; - *_symbolType = ELF32_ST_TYPE(symbol->st_info) == STT_FUNC - ? B_SYMBOL_TYPE_TEXT : B_SYMBOL_TYPE_DATA; + *_symbolType = symbol->Type() == STT_FUNC ? B_SYMBOL_TYPE_TEXT + : B_SYMBOL_TYPE_DATA; return B_OK; } @@ -268,7 +267,7 @@ ImageFile::_LoadFile(const char* path, addr_t* _textAddress, size_t* _textSize, return errno; fFileSize = st.st_size; - if (fFileSize < sizeof(Elf32_Ehdr)) + if (fFileSize < (off_t)sizeof(elf_ehdr)) return B_NOT_AN_EXECUTABLE; // map it @@ -277,7 +276,7 @@ ImageFile::_LoadFile(const char* path, addr_t* _textAddress, size_t* _textSize, return errno; // examine the elf header - Elf32_Ehdr* elfHeader = (Elf32_Ehdr*)fMappedFile; + elf_ehdr* elfHeader = (elf_ehdr*)fMappedFile; if (memcmp(elfHeader->e_ident, ELF_MAGIC, 4) != 0) return B_NOT_AN_EXECUTABLE; @@ -286,27 +285,28 @@ ImageFile::_LoadFile(const char* path, addr_t* _textAddress, size_t* _textSize, // verify the location of the program headers int32 programHeaderCount = elfHeader->e_phnum; - if (elfHeader->e_phoff < sizeof(Elf32_Ehdr) - || elfHeader->e_phentsize < sizeof(Elf32_Phdr) - || elfHeader->e_phoff + programHeaderCount * elfHeader->e_phentsize + if (elfHeader->e_phoff < sizeof(elf_ehdr) + || elfHeader->e_phentsize < sizeof(elf_phdr) + || (off_t)(elfHeader->e_phoff + programHeaderCount + * elfHeader->e_phentsize) > fFileSize) { return B_NOT_AN_EXECUTABLE; } - Elf32_Phdr* programHeaders - = (Elf32_Phdr*)(fMappedFile + elfHeader->e_phoff); + elf_phdr* programHeaders + = (elf_phdr*)(fMappedFile + elfHeader->e_phoff); // verify the location of the section headers int32 sectionCount = elfHeader->e_shnum; - if (elfHeader->e_shoff < sizeof(Elf32_Ehdr) - || elfHeader->e_shentsize < sizeof(Elf32_Shdr) - || elfHeader->e_shoff + sectionCount * elfHeader->e_shentsize + if (elfHeader->e_shoff < sizeof(elf_ehdr) + || elfHeader->e_shentsize < sizeof(elf_shdr) + || (off_t)(elfHeader->e_shoff + sectionCount * elfHeader->e_shentsize) > fFileSize) { return B_NOT_AN_EXECUTABLE; } - Elf32_Shdr* sectionHeaders - = (Elf32_Shdr*)(fMappedFile + elfHeader->e_shoff); + elf_shdr* sectionHeaders + = (elf_shdr*)(fMappedFile + elfHeader->e_shoff); // find the text and data segment -- we need load address and size *_textAddress = 0; @@ -314,7 +314,7 @@ ImageFile::_LoadFile(const char* path, addr_t* _textAddress, size_t* _textSize, *_dataAddress = 0; *_dataSize = 0; for (int32 i = 0; i < programHeaderCount; i++) { - Elf32_Phdr* header = (Elf32_Phdr*) + elf_phdr* header = (elf_phdr*) ((uint8*)programHeaders + i * elfHeader->e_phentsize); if (header->p_type == PT_LOAD) { if ((header->p_flags & PF_WRITE) == 0) { @@ -330,25 +330,27 @@ ImageFile::_LoadFile(const char* path, addr_t* _textAddress, size_t* _textSize, // find the symbol table for (int32 i = 0; i < elfHeader->e_shnum; i++) { - Elf32_Shdr* sectionHeader = (Elf32_Shdr*) + elf_shdr* sectionHeader = (elf_shdr*) ((uint8*)sectionHeaders + i * elfHeader->e_shentsize); if (sectionHeader->sh_type == SHT_SYMTAB) { - Elf32_Shdr& stringHeader = *(Elf32_Shdr*) + elf_shdr& stringHeader = *(elf_shdr*) ((uint8*)sectionHeaders + sectionHeader->sh_link * elfHeader->e_shentsize); if (stringHeader.sh_type != SHT_STRTAB) return B_BAD_DATA; - if (sectionHeader->sh_offset + sectionHeader->sh_size > fFileSize - || stringHeader.sh_offset + stringHeader.sh_size > fFileSize) { + if ((off_t)(sectionHeader->sh_offset + sectionHeader->sh_size) + > fFileSize + || (off_t)(stringHeader.sh_offset + stringHeader.sh_size) + > fFileSize) { return B_BAD_DATA; } - fSymbolTable = (Elf32_Sym*)(fMappedFile + sectionHeader->sh_offset); + fSymbolTable = (elf_sym*)(fMappedFile + sectionHeader->sh_offset); fStringTable = (char*)(fMappedFile + stringHeader.sh_offset); - fSymbolCount = sectionHeader->sh_size / sizeof(Elf32_Sym); + fSymbolCount = sectionHeader->sh_size / sizeof(elf_sym); fStringTableSize = stringHeader.sh_size; return B_OK; @@ -388,7 +390,7 @@ KernelImage::Init(const image_info& info) return error; // allocate the tables - fSymbolTable = new(std::nothrow) Elf32_Sym[fSymbolCount]; + fSymbolTable = new(std::nothrow) elf_sym[fSymbolCount]; fStringTable = new(std::nothrow) char[fStringTableSize]; if (fSymbolTable == NULL || fStringTable == NULL) return B_NO_MEMORY; diff --git a/src/kits/debug/Image.h b/src/kits/debug/Image.h index 5a691de..aa4e76d 100644 --- a/src/kits/debug/Image.h +++ b/src/kits/debug/Image.h @@ -8,6 +8,7 @@ #include <stdio.h> +#include <elf_common.h> #include <image.h> #include <OS.h> @@ -16,7 +17,6 @@ struct image_t; struct runtime_loader_debug_area; -struct Elf32_Sym; namespace BPrivate { @@ -35,7 +35,7 @@ public: { return (addr_t)fInfo.text; } size_t TextSize() const { return fInfo.text_size; } - virtual const Elf32_Sym* LookupSymbol(addr_t address, + virtual const elf_sym* LookupSymbol(addr_t address, addr_t* _baseAddress, const char** _symbolName, size_t *_symbolNameLen, @@ -60,7 +60,7 @@ public: SymbolTableBasedImage(); virtual ~SymbolTableBasedImage(); - virtual const Elf32_Sym* LookupSymbol(addr_t address, + virtual const elf_sym* LookupSymbol(addr_t address, addr_t* _baseAddress, const char** _symbolName, size_t *_symbolNameLen, @@ -76,7 +76,7 @@ protected: protected: addr_t fLoadDelta; - Elf32_Sym* fSymbolTable; + elf_sym* fSymbolTable; char* fStringTable; int32 fSymbolCount; size_t fStringTableSize; diff --git a/src/kits/debug/SymbolLookup.cpp b/src/kits/debug/SymbolLookup.cpp index d29f4e8..2665eea 100644 --- a/src/kits/debug/SymbolLookup.cpp +++ b/src/kits/debug/SymbolLookup.cpp @@ -196,7 +196,7 @@ public: const image_t* image, int32 symbolCount); virtual ~LoadedImage(); - virtual const Elf32_Sym* LookupSymbol(addr_t address, + virtual const elf_sym* LookupSymbol(addr_t address, addr_t* _baseAddress, const char** _symbolName, size_t *_symbolNameLen, @@ -251,7 +251,7 @@ SymbolLookup::Init() // find the runtime loader debug area runtime_loader_debug_area *remoteDebugArea = NULL; - int32 cookie = 0; + ssize_t cookie = 0; area_info areaInfo; while (get_next_area_info(fTeam, &cookie, &areaInfo) == B_OK) { if (strcmp(areaInfo.name, RUNTIME_LOADER_DEBUG_AREA_NAME) == 0) { @@ -340,7 +340,7 @@ SymbolLookup::LookupSymbolAddress(addr_t address, addr_t *_baseAddress, if (_imageName != NULL) *_imageName = image->Name(); - const Elf32_Sym* symbolFound = image->LookupSymbol(address, _baseAddress, + const elf_sym* symbolFound = image->LookupSymbol(address, _baseAddress, _symbolName, _symbolNameLen, _exactMatch); TRACE(("SymbolLookup::LookupSymbolAddress(): done: symbol: %p, image name: " @@ -557,7 +557,7 @@ SymbolLookup::LoadedImage::~LoadedImage() } -const Elf32_Sym* +const elf_sym* SymbolLookup::LoadedImage::LookupSymbol(addr_t address, addr_t* _baseAddress, const char** _symbolName, size_t *_symbolNameLen, bool *_exactMatch) const { @@ -566,7 +566,7 @@ SymbolLookup::LoadedImage::LookupSymbol(addr_t address, addr_t* _baseAddress, (void*)fImage->regions[0].vmstart, fImage->regions[0].size)); // search the image for the symbol - const struct Elf32_Sym *symbolFound = NULL; + const elf_sym *symbolFound = NULL; addr_t deltaFound = INT_MAX; bool exactMatch = false; const char *symbolName = NULL; @@ -575,7 +575,7 @@ SymbolLookup::LoadedImage::LookupSymbol(addr_t address, addr_t* _baseAddress, const elf_region_t *textRegion = fImage->regions; // local for (int32 i = 0; i < symbolCount; i++) { - const struct Elf32_Sym *symbol = &fSymbolLookup->Read(fImage->syms[i]); + const elf_sym *symbol = &fSymbolLookup->Read(fImage->syms[i]); // The symbol table contains not only symbols referring to functions // and data symbols within the shared object, but also referenced @@ -584,8 +584,7 @@ SymbolLookup::LoadedImage::LookupSymbol(addr_t address, addr_t* _baseAddress, // that have an st_value != 0 (0 seems to be an indication for a // symbol defined elsewhere -- couldn't verify that in the specs // though). - if ((ELF32_ST_TYPE(symbol->st_info) != STT_FUNC - && ELF32_ST_TYPE(symbol->st_info) != STT_OBJECT) + if ((symbol->Type() != STT_FUNC && symbol->Type() != STT_OBJECT) || symbol->st_value == 0 || symbol->st_value + symbol->st_size + textRegion->delta > textRegion->vmstart + textRegion->size) { @@ -643,10 +642,9 @@ SymbolLookup::LoadedImage::NextSymbol(int32& iterator, const char** _symbolName, if (++iterator >= fSymbolCount) return B_ENTRY_NOT_FOUND; - const struct Elf32_Sym* symbol + const elf_sym* symbol = &fSymbolLookup->Read(fImage->syms[iterator]); - if ((ELF32_ST_TYPE(symbol->st_info) != STT_FUNC - && ELF32_ST_TYPE(symbol->st_info) != STT_OBJECT) + if ((symbol->Type() != STT_FUNC && symbol->Type() != STT_OBJECT) || symbol->st_value == 0) { continue; } @@ -656,8 +654,8 @@ SymbolLookup::LoadedImage::NextSymbol(int32& iterator, const char** _symbolName, *_symbolNameLen = fSymbolLookup->_SymbolNameLen(*_symbolName); *_symbolAddress = symbol->st_value + fTextDelta; *_symbolSize = symbol->st_size; - *_symbolType = ELF32_ST_TYPE(symbol->st_info) == STT_FUNC - ? B_SYMBOL_TYPE_TEXT : B_SYMBOL_TYPE_DATA; + *_symbolType = symbol->Type() == STT_FUNC ? B_SYMBOL_TYPE_TEXT + : B_SYMBOL_TYPE_DATA; return B_OK; } diff --git a/src/kits/debug/SymbolLookup.h b/src/kits/debug/SymbolLookup.h index b2c78bb..c7890c3 100644 --- a/src/kits/debug/SymbolLookup.h +++ b/src/kits/debug/SymbolLookup.h @@ -16,7 +16,6 @@ struct image_t; struct runtime_loader_debug_area; -struct Elf32_Sym; namespace BPrivate { diff --git a/src/kits/debug/arch/x86_64/arch_debug_support.cpp b/src/kits/debug/arch/x86_64/arch_debug_support.cpp new file mode 100644 index 0000000..83f6b35 --- /dev/null +++ b/src/kits/debug/arch/x86_64/arch_debug_support.cpp @@ -0,0 +1,52 @@ +/* + * Copyright 2005, Ingo Weinhold, bonefish@xxxxxxxxxxxxx + * Copyright 2012, Alex Smith, alex@xxxxxxxxxxxxxxxxx + * Distributed under the terms of the MIT License. + */ + + +#include <debug_support.h> + +#include "arch_debug_support.h" + + +struct stack_frame { + struct stack_frame *previous; + void *return_address; +}; + + +status_t +arch_debug_get_instruction_pointer(debug_context *context, thread_id thread, + void **ip, void **stackFrameAddress) +{ + // get the CPU state + debug_cpu_state cpuState; + status_t error = debug_get_cpu_state(context, thread, NULL, &cpuState); + if (error != B_OK) + return error; + + *ip = (void*)cpuState.rip; + *stackFrameAddress = (void*)cpuState.rbp; + + return B_OK; +} + + +status_t +arch_debug_get_stack_frame(debug_context *context, void *stackFrameAddress, + debug_stack_frame_info *stackFrameInfo) +{ + stack_frame stackFrame; + ssize_t bytesRead = debug_read_memory(context, stackFrameAddress, + &stackFrame, sizeof(stackFrame)); + if (bytesRead < B_OK) + return bytesRead; + if (bytesRead != sizeof(stackFrame)) + return B_ERROR; + + stackFrameInfo->frame = stackFrameAddress; + stackFrameInfo->parent_frame = stackFrame.previous; + stackFrameInfo->return_address = stackFrame.return_address; + return B_OK; +} ############################################################################ Commit: a3802ca96702d7011ad4967428c38f196b07480c Author: Alex Smith <alex@xxxxxxxxxxxxxxxx> Date: Tue Aug 7 19:24:55 2012 UTC x86_64 support for GDB. As mentioned in one of the previous commits, breakpoints don't work properly yet, and I haven't done much extensive testing yet, but the basic functionality works. ---------------------------------------------------------------------------- diff --git a/build/jam/Haiku64Image b/build/jam/Haiku64Image index 288c5f1..506454c 100644 --- a/build/jam/Haiku64Image +++ b/build/jam/Haiku64Image @@ -23,14 +23,14 @@ SYSTEM_BIN = "[" addattr base64 basename bash beep cal cat catattr chgrp chmod chown chroot cksum clear clockconfig cmp collectcatkeys comm compress copyattr cp csplit cut date dd diff diff3 dircolors dirname df du dumpcatalog echo eject env error expand expr factor false find finddir - fmt fold fortune gawk gzip gzexe getlimits groups head hostname id + fmt fold fortune gawk gdb gzip gzexe getlimits groups head hostname id <bin>install isvolume join kernel_debugger kill less lessecho lesskey link linkcatkeys listdev ln locale locate logger logname ls md5sum mkdir mkfifo mktemp mount mountvolume mv nl nohup nproc od paste patch pathchk pr printenv printf ps ptx pwd readlink rm rmattr rmdir safemode sdiff seq - sha1sum shred shuf sleep sort split stat stty su sum sync sysinfo tac tail - tee test timeout touch tr true truncate tsort tty unexpand uname uniq - unlink unmount unzip <bin>updatedb waitfor wc whoami xargs xres yes + sha1sum shred shuf sleep sort split stat strace stty su sum sync sysinfo + tac tail tee test timeout touch tr true truncate tsort tty unexpand uname + uniq unlink unmount unzip <bin>updatedb waitfor wc whoami xargs xres yes zdiff zforce zgrep zip zipcloak <bin>zipgrep zipnote zipsplit zmore znew ; @@ -40,7 +40,7 @@ SYSTEM_PREFERENCES = ; SYSTEM_DEMOS = ; -SYSTEM_LIBS = libbe.so libbnetapi.so libnetwork.so +SYSTEM_LIBS = libbe.so libbnetapi.so libdebug.so libnetwork.so libroot.so libroot-addon-icu.so libtextencoding.so libtracker.so libtranslation.so $(HAIKU_SHARED_LIBSTDC++) $(HAIKU_SHARED_LIBSUPC++) diff --git a/src/bin/debug/strace/Context.cpp b/src/bin/debug/strace/Context.cpp index 11212f8..9a9eb82 100644 --- a/src/bin/debug/strace/Context.cpp +++ b/src/bin/debug/strace/Context.cpp @@ -20,13 +20,13 @@ Context::FormatSigned(int64 value, int bytes) const // decimal if (fDecimal) { - snprintf(tmp, sizeof(tmp), "%lld", value); + snprintf(tmp, sizeof(tmp), "%" B_PRId64, value); return tmp; } // hex - snprintf(tmp, sizeof(tmp), "0x%llx", value); + snprintf(tmp, sizeof(tmp), "0x%" B_PRIx64, value); // Negative numbers are expanded when being converted to int64. Hence // we skip all but the last 2 * bytes hex digits to retain the original @@ -49,7 +49,7 @@ string Context::FormatUnsigned(uint64 value) const { char tmp[32]; - snprintf(tmp, sizeof(tmp), fDecimal ? "%llu" : "0x%llx", value); + snprintf(tmp, sizeof(tmp), fDecimal ? "%" B_PRIu64 : "0x%" B_PRIx64, value); return tmp; } @@ -57,7 +57,7 @@ string Context::FormatFlags(uint64 value) const { char tmp[32]; - snprintf(tmp, sizeof(tmp), "0x%llx", value); + snprintf(tmp, sizeof(tmp), "0x%" B_PRIx64, value); return tmp; } diff --git a/src/bin/debug/strace/strace.cpp b/src/bin/debug/strace/strace.cpp index dbb332f..046efbd 100644 --- a/src/bin/debug/strace/strace.cpp +++ b/src/bin/debug/strace/strace.cpp @@ -528,8 +528,8 @@ main(int argc, const char *const *argv) thread_info threadInfo; status_t error = get_thread_info(threadID, &threadInfo); if (error != B_OK) { - fprintf(stderr, "%s: Failed to get info for thread %ld: %s\n", - kCommandName, threadID, strerror(error)); + fprintf(stderr, "%s: Failed to get info for thread %" B_PRId32 + ": %s\n", kCommandName, threadID, strerror(error)); exit(1); } teamID = threadInfo.team; diff --git a/src/bin/gdb/bfd/Jamfile b/src/bin/gdb/bfd/Jamfile index 5335660..34eb556 100644 --- a/src/bin/gdb/bfd/Jamfile +++ b/src/bin/gdb/bfd/Jamfile @@ -8,6 +8,9 @@ SubDirSysHdrs [ FDirName $(HAIKU_TOP) src bin gawk intl ] ; SubDirCcFlags -DHAVE_CONFIG_H -D_GNU_SOURCE ; +local bfd32SelectVecs = &bfd_elf32_little_generic_vec,&bfd_elf32_big_generic_vec ; +local bfd64SelectVecs = &bfd_elf64_little_generic_vec,&bfd_elf64_big_generic_vec ; + # architecture specific sources local bfdArchSources ; if $(TARGET_ARCH) = x86 { @@ -20,7 +23,7 @@ if $(TARGET_ARCH) = x86 { ObjectCcFlags archures.c targets.c : -DDEFAULT_VECTOR=bfd_elf32_i386_vec - -DSELECT_VECS=\"&bfd_elf32_i386_vec,&i386pe_vec,&i386pei_vec,&bfd_elf32_little_generic_vec,&bfd_elf32_big_generic_vec\" + -DSELECT_VECS=\"&bfd_elf32_i386_vec,&i386pe_vec,&i386pei_vec,$(bfd32SelectVecs)\" -DSELECT_ARCHITECTURES=\"&bfd_i386_arch\" -DHAVE_bfd_elf32_i386_vec -DHAVE_i386pe_vec @@ -28,6 +31,26 @@ if $(TARGET_ARCH) = x86 { -DHAVE_bfd_elf32_little_generic_vec -DHAVE_bfd_elf32_big_generic_vec ; +} else if $(TARGET_ARCH) = x86_64 { + bfdArchSources = + cpu-i386.c + elf64-x86-64.c + elf32-i386.c + elf64.c + elf64-gen.c + ; + + ObjectCcFlags archures.c targets.c : + -DDEFAULT_VECTOR=bfd_elf64_x86_64_vec + -DSELECT_VECS=\"&bfd_elf64_x86_64_vec,&bfd_elf32_i386_vec,$(bfd32SelectVecs),$(bfd64SelectVecs)\" + -DSELECT_ARCHITECTURES=\"&bfd_i386_arch\" + -DHAVE_bfd_elf64_x86_64_vec + -DHAVE_bfd_elf32_i386_vec + -DHAVE_bfd_elf64_little_generic_vec + -DHAVE_bfd_elf64_big_generic_vec + -DHAVE_bfd_elf32_little_generic_vec + -DHAVE_bfd_elf32_big_generic_vec + ; } else if $(TARGET_ARCH) = ppc { bfdArchSources = cpu-powerpc.c @@ -81,7 +104,10 @@ local bfdGenericSources = elf-strtab.c ; -local bfdGeneratedSources = peigen.c ; +local bfdGeneratedSources ; +if $(TARGET_ARCH) != x86_64 { + bfdGeneratedSources = peigen.c ; +} local bfdAllSources = $(bfdBaseSources) @@ -167,6 +193,7 @@ local bfdHeadersToCopy = BFDSimpleSed peigen.c : peXXigen.c : s/XX/pe/g ; BFDSimpleSed elf32-target.h : elfxx-target.h : s/NN/32/g ; +BFDSimpleSed elf64-target.h : elfxx-target.h : s/NN/64/g ; BFDFileSed targmatch.h : config.bfd : targmatch.sed ; BFDCopyConfigHeaders $(bfdHeadersToCopy) ; @@ -174,7 +201,8 @@ BFDCopyConfigHeaders $(bfdHeadersToCopy) ; # depend on them. local bfdGeneratedHeaders - = [ FGristFiles $(bfdHeadersToCopy) elf32-target.h targmatch.h ] ; + = [ FGristFiles $(bfdHeadersToCopy) elf32-target.h elf64-target.h + targmatch.h ] ; Depends gdb-bfd-generated-headers : $(bfdGeneratedHeaders) ; NotFile gdb-bfd-generated-headers ; diff --git a/src/bin/gdb/bfd/config-x86_64/bfd-in3.h b/src/bin/gdb/bfd/config-x86_64/bfd-in3.h new file mode 100644 index 0000000..ba10b28 --- /dev/null +++ b/src/bin/gdb/bfd/config-x86_64/bfd-in3.h @@ -0,0 +1,4645 @@ +/* DO NOT EDIT! -*- buffer-read-only: t -*- This file is automatically + generated from "bfd-in.h", "init.c", "opncls.c", "libbfd.c", + "bfdio.c", "bfdwin.c", "section.c", "archures.c", "reloc.c", + "syms.c", "bfd.c", "archive.c", "corefile.c", "targets.c", "format.c", + "linker.c" and "simple.c". + Run "make headers" in your build bfd/ to regenerate. */ + +/* Main header file for the bfd library -- portable access to object files. + + Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, + 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc. + + Contributed by Cygnus Support. + + This file is part of BFD, the Binary File Descriptor library. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#ifndef __BFD_H_SEEN__ +#define __BFD_H_SEEN__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "ansidecl.h" +#include "symcat.h" +#if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE) +#ifndef SABER +/* This hack is to avoid a problem with some strict ANSI C preprocessors. + The problem is, "32_" is not a valid preprocessing token, and we don't + want extra underscores (e.g., "nlm_32_"). The XCONCAT2 macro will + cause the inner CONCAT2 macros to be evaluated first, producing + still-valid pp-tokens. Then the final concatenation can be done. */ +#undef CONCAT4 +#define CONCAT4(a,b,c,d) XCONCAT2(CONCAT2(a,b),CONCAT2(c,d)) +#endif +#endif + +/* The word size used by BFD on the host. This may be 64 with a 32 + bit target if the host is 64 bit, or if other 64 bit targets have + been selected with --enable-targets, or if --enable-64-bit-bfd. */ +#define BFD_ARCH_SIZE 64 + +/* The word size of the default bfd target. */ +#define BFD_DEFAULT_TARGET_SIZE 64 + +#define BFD_HOST_64BIT_LONG 1 +#define BFD_HOST_LONG_LONG 1 +#define BFD_HOST_64_BIT long +#define BFD_HOST_U_64_BIT unsigned long +typedef BFD_HOST_64_BIT bfd_int64_t; +typedef BFD_HOST_U_64_BIT bfd_uint64_t; + +#if BFD_ARCH_SIZE >= 64 +#define BFD64 +#endif + +#ifndef INLINE +#if __GNUC__ >= 2 +#define INLINE __inline__ +#else +#define INLINE +#endif +#endif + +/* Forward declaration. */ +typedef struct bfd bfd; + [ *** diff truncated: 10856 lines dropped *** ]