Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libc.gmk
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ C_UNISTD := \
unistd/ttyname.o \
unistd/ttyname_r.o \
unistd/ualarm.o \
unistd/unix_paths_enabled.o \
unistd/unlink.o \
unistd/usleep.o \
unistd/wildcard_expand.o
Expand Down
2 changes: 1 addition & 1 deletion library/ctype/isalnum.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

int
isalnum(int c) {
DECLARE_LOCALEBASE();
int result;
struct _clib4 *__clib4 = __CLIB4;
DECLARE_LOCALEBASE_R(__clib4);

ENTER();
SHOWVALUE(c);
Expand Down
2 changes: 1 addition & 1 deletion library/ctype/isalpha.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

int
isalpha(int c) {
DECLARE_LOCALEBASE();
int result;
struct _clib4 *__clib4 = __CLIB4;
DECLARE_LOCALEBASE_R(__clib4);

ENTER();
SHOWVALUE(c);
Expand Down
2 changes: 1 addition & 1 deletion library/ctype/iscntrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

int
iscntrl(int c) {
DECLARE_LOCALEBASE();
int result;
struct _clib4 *__clib4 = __CLIB4;
DECLARE_LOCALEBASE_R(__clib4);

ENTER();
SHOWVALUE(c);
Expand Down
2 changes: 1 addition & 1 deletion library/ctype/isdigit.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ isdigit(int c) {

int
__isdigit_r(struct _clib4 *__clib4, int c) {
DECLARE_LOCALEBASE();
DECLARE_LOCALEBASE_R(__clib4);
int result;

ENTER();
Expand Down
2 changes: 1 addition & 1 deletion library/ctype/isgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

int
isgraph(int c) {
DECLARE_LOCALEBASE();
int result;
struct _clib4 *__clib4 = __CLIB4;
DECLARE_LOCALEBASE_R(__clib4);

ENTER();
SHOWVALUE(c);
Expand Down
2 changes: 1 addition & 1 deletion library/ctype/islower.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

int
islower(int c) {
DECLARE_LOCALEBASE();
int result;
struct _clib4 *__clib4 = __CLIB4;
DECLARE_LOCALEBASE_R(__clib4);

ENTER();
SHOWVALUE(c);
Expand Down
2 changes: 1 addition & 1 deletion library/ctype/isprint.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

int
isprint(int c) {
DECLARE_LOCALEBASE();
int result;
struct _clib4 *__clib4 = __CLIB4;
DECLARE_LOCALEBASE_R(__clib4);

ENTER();
SHOWVALUE(c);
Expand Down
2 changes: 1 addition & 1 deletion library/ctype/ispunct.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

int
ispunct(int c) {
DECLARE_LOCALEBASE();
int result;
struct _clib4 *__clib4 = __CLIB4;
DECLARE_LOCALEBASE_R(__clib4);

ENTER();
SHOWVALUE(c);
Expand Down
2 changes: 1 addition & 1 deletion library/ctype/isspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ isspace(int c) {

int
__isspace_r(struct _clib4 *__clib4, int c) {
DECLARE_LOCALEBASE();
DECLARE_LOCALEBASE_R(__clib4);
int result;

ENTER();
Expand Down
2 changes: 1 addition & 1 deletion library/ctype/isupper.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

int
isupper(int c) {
DECLARE_LOCALEBASE();
int result;
struct _clib4 *__clib4 = __CLIB4;
DECLARE_LOCALEBASE_R(__clib4);

ENTER();
SHOWVALUE(c);
Expand Down
2 changes: 1 addition & 1 deletion library/ctype/isxdigit.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

int
isxdigit(int c) {
DECLARE_LOCALEBASE();
int result;
struct _clib4 *__clib4 = __CLIB4;
DECLARE_LOCALEBASE_R(__clib4);

ENTER();
SHOWVALUE(c);
Expand Down
2 changes: 1 addition & 1 deletion library/ctype/tolower.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

int
tolower(int c) {
DECLARE_LOCALEBASE();
int result;
struct _clib4 *__clib4 = __CLIB4;
DECLARE_LOCALEBASE_R(__clib4);

__locale_lock(__clib4);

Expand Down
2 changes: 1 addition & 1 deletion library/ctype/toupper.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

int
toupper(int c) {
DECLARE_LOCALEBASE();
int result;
struct _clib4 *__clib4 = __CLIB4;
DECLARE_LOCALEBASE_R(__clib4);

__locale_lock(__clib4);

Expand Down
70 changes: 35 additions & 35 deletions library/debug/backtrace_symbols.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,54 +17,54 @@ backtrace_symbols(void *const *buffer, int size) {

if (size <= 0)
return NULL;
if (!__clib4->__dl_root_handle != 0)
return NULL;

struct ElfIFace *IElf = __clib4->IElf;

struct Hook symbol_hook;
symbol_hook.h_Entry = (ULONG (*)())amigaos_symbols_callback;
symbol_hook.h_Data = NULL;
ScanSymbolTable(__clib4->__dl_root_handle, &symbol_hook, NULL);
DECLARE_DEBUGBASE();

// Allocate array of strings
char **symbols = __malloc_r(__clib4, size * sizeof(char *));
if (!symbols)
return NULL;

struct Elf32_SymbolQuery query;
char nameBuffer[256] = {0};
query.Flags = ELF32_SQ_BYVALUE | ELF32_SQ_LOAD;
query.NameLength = 255;
query.Name = nameBuffer;

for (int i = 0; i < size; i++) {
BOOL found = FALSE;
ULONG fileBuffer;

query.Value = (uint32) buffer[i];

SymbolQuery(__clib4->__dl_root_handle, 1, &query);
if (query.Found) {
// Format: "<hex-addr> <func>+<offset> [<lib>]"
// Format: "<hex-addr> <func>+<offset> [<lib>]"
uint32 addr = (uint32) buffer[i];
struct DebugSymbol *symbol = ObtainDebugSymbol((APTR) addr, NULL);
if (symbol) {
const int max_len = 256;
symbols[i] = __calloc_r(__clib4, 1, max_len);
if (symbols[i]) {
found = TRUE;
GetElfAttrsTags(__clib4->__dl_root_handle, EAT_FileName, &fileBuffer, TAG_DONE);
snprintf(
symbols[i],
max_len,
"%p %s+0x%lx [%s]",
buffer[i],
query.Name ? query.Name : "???",
query.Sym.st_value,
(STRPTR) fileBuffer
);

switch (symbol->Type) {
case DEBUG_SYMBOL_68K_MODULE:
snprintf(symbols[i], max_len, "%p %s+0x%lx [68k module]", addr, symbol->Name, symbol->Offset);
break;
case DEBUG_SYMBOL_NATIVE_MODULE:
snprintf(symbols[i], max_len, "%p %s+0x%lx [native module]", addr, symbol->Name, symbol->Offset);
break;
case DEBUG_SYMBOL_KERNEL_MODULE:
snprintf(symbols[i], max_len, "%p %s+0x%lx [kernel module]", addr, symbol->Name, addr);
break;
case DEBUG_SYMBOL_MODULE:
case DEBUG_SYMBOL_MODULE_STABS:
snprintf(
symbols[i],
max_len,
"%p %s+0x%lx [%s]",
buffer[i],
symbol->Name ? symbol->Name : "???",
symbol->Offset,
symbol->SourceFileName ? symbol->SourceFileName : ""
);
break;
default:
// Fallback to address
snprintf(symbols[i], 20, "%p", buffer[i]);
break;
}
}
ReleaseDebugSymbol(symbol);
}

if (!found) {
else {
// Fallback: Just the address
symbols[i] = __calloc_r(__clib4, 1, 20); // Enough for "0x<hex>"
if (symbols[i]) {
Expand Down
73 changes: 39 additions & 34 deletions library/debug/backtrace_symbols_fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,50 @@ backtrace_symbols_fd(void *const *buffer, int size, int fd) {

if (size <= 0)
return;
if (!__clib4->__dl_root_handle != 0)
return;

struct ElfIFace *IElf = __clib4->IElf;

struct Hook symbol_hook;
symbol_hook.h_Entry = (ULONG (*)())amigaos_symbols_callback;
symbol_hook.h_Data = NULL;
ScanSymbolTable(__clib4->__dl_root_handle, &symbol_hook, NULL);

struct Elf32_SymbolQuery query;
char nameBuffer[256] = {0};

query.Flags = ELF32_SQ_BYVALUE | ELF32_SQ_LOAD;
query.NameLength = 255;
query.Name = nameBuffer;
DECLARE_DEBUGBASE();

for (int i = 0; i < size; i++) {
BOOL found = FALSE;
ULONG fileBuffer;

query.Value = (uint32) buffer[i];

SymbolQuery(__clib4->__dl_root_handle, 1, &query);
if (query.Found) {
found = TRUE;
// Format: "<hex-addr> <func>+<offset> [<lib>]"
uint32 addr = (uint32) buffer[i];
struct DebugSymbol *symbol = ObtainDebugSymbol((APTR) addr, NULL);
if (symbol) {
const int max_len = 256;
char line[256];
GetElfAttrsTags(__clib4->__dl_root_handle, EAT_FileName, &fileBuffer, TAG_DONE);
int len = snprintf(
line, sizeof(line), "%p %s+0x%lx [%s]\n",
buffer[i],
query.Name ? query.Name : "???",
query.Sym.st_value,
(STRPTR) fileBuffer
);
write(fd, line, len);
}
int len = 0;

if (!found) {
switch (symbol->Type) {
case DEBUG_SYMBOL_68K_MODULE:
len = snprintf(line, max_len, "%p %s+0x%lx [68k module]\n", addr, symbol->Name, symbol->Offset);
break;
case DEBUG_SYMBOL_NATIVE_MODULE:
len = snprintf(line, max_len, "%p %s+0x%lx [native module]\n", addr, symbol->Name, symbol->Offset);
break;
case DEBUG_SYMBOL_KERNEL_MODULE:
len = snprintf(line, max_len, "%p %s+0x%lx [kernel module]\n", addr, symbol->Name, addr);
break;
case DEBUG_SYMBOL_MODULE:
case DEBUG_SYMBOL_MODULE_STABS:
len = snprintf(
line,
max_len,
"%p %s+0x%lx [%s]\n",
buffer[i],
symbol->Name ? symbol->Name : "???",
symbol->Offset,
symbol->SourceFileName ? symbol->SourceFileName : ""
);
break;
default:
// Fallback to address
len = snprintf(line, 20, "%p", buffer[i]);
break;
}
write(fd, line, len);
ReleaseDebugSymbol(symbol);
}
else {
// Fallback: Just the address
char line[20];
int len = snprintf(line, sizeof(line), "%p\n", buffer[i]);
write(fd, line, len);
Expand Down
2 changes: 2 additions & 0 deletions library/dos.h
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,8 @@ struct _clib4 {

int local_raised_signals_blocked;
int isTZSet;

struct DebugIFace *__IDebug;
};

#ifndef __getClib4
Expand Down
1 change: 1 addition & 0 deletions library/include/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ extern void enableAltivec(void);
extern void disableAltivec(void);
extern void enableOptimizedFunctions(void);
extern void disableOptimizedFunctions(void);
extern int unixPathsEnabled(void);

extern char *getcwd(char * buffer, size_t buffer_size);
extern char *getwd(char *buf);
Expand Down
12 changes: 12 additions & 0 deletions library/libc_init_global.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ reent_init(struct _clib4 *__clib4, BOOL fallback) {
.__num_iob = 0,
._iob_pool = NULL,
.isTZSet = 0,
.__IDebug = NULL,
};

if (!__clib4->__random_lock || !__clib4->__pipe_semaphore) {
Expand Down Expand Up @@ -370,6 +371,13 @@ reent_init(struct _clib4 *__clib4, BOOL fallback) {
}
}

__clib4->__IDebug = (struct DebugIFace *) GetInterface((struct Library *) IExec->Data.LibBase, "debug", 1, NULL);
D(("__clib4->__IDebug %p", __clib4->__IDebug));
if (!__clib4->__IDebug) {
D(("Cannot get IDebug interface"));
goto out;
}

/*
* Next: Get Elf handle associated with the currently running process.
* ElfBase is opened in crtbegin.c that is called before the
Expand Down Expand Up @@ -445,6 +453,10 @@ reent_exit(struct _clib4 *__clib4, BOOL fallback) {
__clib4->wide_status = NULL;
}

/* Drop IDebug interface */
if (__clib4->__IDebug)
DropInterface((struct Interface *) __clib4->__IDebug);

/* Remove random semaphore */
SHOWMSG("Delete __random_lock semaphore");
__delete_semaphore(__clib4->__random_lock);
Expand Down
6 changes: 3 additions & 3 deletions library/locale/init_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void __close_all_locales(struct _clib4 *__clib4) {
__locale_lock(__clib4);

if (__clib4->__LocaleBase != NULL) {
DECLARE_LOCALEBASE();
DECLARE_LOCALEBASE_R(__clib4);

int i;

Expand Down Expand Up @@ -45,7 +45,7 @@ void __locale_exit(struct _clib4 *__clib4) {
__locale_lock(__clib4);

if (__clib4->__LocaleBase != NULL) {
DECLARE_LOCALEBASE();
DECLARE_LOCALEBASE_R(__clib4);

__close_all_locales(__clib4);

Expand Down Expand Up @@ -109,7 +109,7 @@ int __locale_init(struct _clib4 *__clib4) {
}

if (__clib4->__LocaleBase != NULL && __clib4->__default_locale == NULL) {
DECLARE_LOCALEBASE();
DECLARE_LOCALEBASE_R(__clib4);

__clib4->__default_locale = OpenLocale(NULL);
}
Expand Down
Loading