debug messages: implement dynamic debug

Heavily inspired off linux kernel's dynamic debug:
 * add a /sys/kernel/debug/dynamic_debug/control file
 (accessible from linux side in /sys/class/mcos/mcos0/sys/kernel/debug/dynamic_debug/control)
 * read from file to list debug statements (currently limited to 4k in size)
 * write to file with '[file foo ][func bar ][line [x][-[y]]] [+-]p' to change values

Side effects:
 * reindented all linker scripts, there is a new __verbose section
 * added string function strpbrk

Change-Id: I36d7707274dcc3ecaf200075a31a2f0f76021059
This commit is contained in:
Dominique Martinet
2018-05-24 18:17:45 +09:00
parent bc887aab44
commit 3185334c1c
48 changed files with 407 additions and 232 deletions

View File

@@ -30,6 +30,7 @@
#include <debug-monitors.h> #include <debug-monitors.h>
#include <sysreg.h> #include <sysreg.h>
#include <cpufeature.h> #include <cpufeature.h>
#include <debug.h>
#ifdef POSTK_DEBUG_ARCH_DEP_65 #ifdef POSTK_DEBUG_ARCH_DEP_65
#include <hwcap.h> #include <hwcap.h>
#endif /* POSTK_DEBUG_ARCH_DEP_65 */ #endif /* POSTK_DEBUG_ARCH_DEP_65 */
@@ -39,11 +40,8 @@
#include "postk_print_sysreg.c" #include "postk_print_sysreg.c"
#ifdef DEBUG_PRINT_CPU #ifdef DEBUG_PRINT_CPU
#define dkprintf kprintf #undef DDEBUG_DEFAULT
#define ekprintf kprintf #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf kprintf
#endif #endif
#define BUG_ON(condition) do { if (condition) { kprintf("PANIC: %s: %s(line:%d)\n",\ #define BUG_ON(condition) do { if (condition) { kprintf("PANIC: %s: %s(line:%d)\n",\

View File

@@ -9,15 +9,13 @@
#include <prctl.h> #include <prctl.h>
#include <cpufeature.h> #include <cpufeature.h>
#include <kmalloc.h> #include <kmalloc.h>
#include <debug.h>
//#define DEBUG_PRINT_FPSIMD //#define DEBUG_PRINT_FPSIMD
#ifdef DEBUG_PRINT_FPSIMD #ifdef DEBUG_PRINT_FPSIMD
#define dkprintf kprintf #undef DDEBUG_DEFAULT
#define ekprintf kprintf #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf kprintf
#endif #endif
#define BUG_ON(condition) do { if (condition) { kprintf("PANIC: %s: %s(line:%d)\n",\ #define BUG_ON(condition) do { if (condition) { kprintf("PANIC: %s: %s(line:%d)\n",\

View File

@@ -7,6 +7,7 @@
#include <process.h> #include <process.h>
#include <string.h> #include <string.h>
#include <elfcore.h> #include <elfcore.h>
#include <debug.h>
#define align32(x) ((((x) + 3) / 4) * 4) #define align32(x) ((((x) + 3) / 4) * 4)
#define alignpage(x) ((((x) + (PAGE_SIZE) - 1) / (PAGE_SIZE)) * (PAGE_SIZE)) #define alignpage(x) ((((x) + (PAGE_SIZE) - 1) / (PAGE_SIZE)) * (PAGE_SIZE))
@@ -14,11 +15,8 @@
//#define DEBUG_PRINT_GENCORE //#define DEBUG_PRINT_GENCORE
#ifdef DEBUG_PRINT_GENCORE #ifdef DEBUG_PRINT_GENCORE
#define dkprintf(...) kprintf(__VA_ARGS__) #undef DDEBUG_DEFAULT
#define ekprintf(...) kprintf(__VA_ARGS__) #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf(...) kprintf(__VA_ARGS__)
#endif #endif
/* /*

View File

@@ -7,15 +7,13 @@
#include <arch/cpu.h> #include <arch/cpu.h>
#include <memory.h> #include <memory.h>
#include <syscall.h> #include <syscall.h>
#include <debug.h>
// #define DEBUG_GICV2 // #define DEBUG_GICV2
#ifdef DEBUG_GICV2 #ifdef DEBUG_GICV2
#define dkprintf(...) kprintf(__VA_ARGS__) #undef DDEBUG_DEFAULT
#define ekprintf(...) kprintf(__VA_ARGS__) #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...)
#define ekprintf(...) kprintf(__VA_ARGS__)
#endif #endif
void *dist_base; void *dist_base;

View File

@@ -7,17 +7,15 @@
#include <cputype.h> #include <cputype.h>
#include <process.h> #include <process.h>
#include <syscall.h> #include <syscall.h>
#include <debug.h>
//#define DEBUG_GICV3 //#define DEBUG_GICV3
#define USE_CAVIUM_THUNDER_X #define USE_CAVIUM_THUNDER_X
#ifdef DEBUG_GICV3 #ifdef DEBUG_GICV3
#define dkprintf(...) kprintf(__VA_ARGS__) #undef DDEBUG_DEFAULT
#define ekprintf(...) kprintf(__VA_ARGS__) #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...)
#define ekprintf(...) kprintf(__VA_ARGS__)
#endif #endif
#ifdef USE_CAVIUM_THUNDER_X #ifdef USE_CAVIUM_THUNDER_X

View File

@@ -14,9 +14,7 @@
#include <context.h> #include <context.h>
#include <kmalloc.h> #include <kmalloc.h>
#include <vdso.h> #include <vdso.h>
#include <debug.h>
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf(...) kprintf(__VA_ARGS__)
#define NOT_IMPLEMENTED() do { kprintf("%s is not implemented\n", __func__); while(1);} while(0) #define NOT_IMPLEMENTED() do { kprintf("%s is not implemented\n", __func__); while(1);} while(0)

View File

@@ -4,16 +4,14 @@
#include <ihk/perfctr.h> #include <ihk/perfctr.h>
#include <errno.h> #include <errno.h>
#include <ihk/debug.h> #include <ihk/debug.h>
#include <debug.h>
#define BIT(nr) (1UL << (nr)) #define BIT(nr) (1UL << (nr))
//#define DEBUG_PRINT_PMU //#define DEBUG_PRINT_PMU
#ifdef DEBUG_PRINT_PMU #ifdef DEBUG_PRINT_PMU
#define dkprintf(...) kprintf(__VA_ARGS__) #undef DDEBUG_DEFAULT
#define ekprintf(...) kprintf(__VA_ARGS__) #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf(...) kprintf(__VA_ARGS__)
#endif #endif

View File

@@ -21,15 +21,13 @@
#include <ihk/debug.h> #include <ihk/debug.h>
#include <compiler.h> #include <compiler.h>
#include <lwk/compiler.h> #include <lwk/compiler.h>
#include <debug.h>
//#define DEBUG_PRINT_PSCI //#define DEBUG_PRINT_PSCI
#ifdef DEBUG_PRINT_PSCI #ifdef DEBUG_PRINT_PSCI
#define dkprintf(...) kprintf(__VA_ARGS__) #undef DDEBUG_DEFAULT
#define ekprintf(...) kprintf(__VA_ARGS__) #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf(...) kprintf(__VA_ARGS__)
#endif #endif
#define PSCI_POWER_STATE_TYPE_POWER_DOWN 1 #define PSCI_POWER_STATE_TYPE_POWER_DOWN 1

View File

@@ -11,15 +11,13 @@
#include <hwcap.h> #include <hwcap.h>
#include <string.h> #include <string.h>
#include <thread_info.h> #include <thread_info.h>
#include <debug.h>
//#define DEBUG_PRINT_SC //#define DEBUG_PRINT_SC
#ifdef DEBUG_PRINT_SC #ifdef DEBUG_PRINT_SC
#define dkprintf kprintf #undef DDEBUG_DEFAULT
#define ekprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0) #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#endif #endif
#define NOT_IMPLEMENTED() do { kprintf("%s is not implemented\n", __func__); while(1);} while(0) #define NOT_IMPLEMENTED() do { kprintf("%s is not implemented\n", __func__); while(1);} while(0)

View File

@@ -14,6 +14,7 @@
#include <prctl.h> #include <prctl.h>
#include <limits.h> #include <limits.h>
#include <syscall.h> #include <syscall.h>
#include <debug.h>
extern void ptrace_report_signal(struct thread *thread, int sig); extern void ptrace_report_signal(struct thread *thread, int sig);
extern void clear_single_step(struct thread *thread); extern void clear_single_step(struct thread *thread);
@@ -27,11 +28,8 @@ static void __check_signal(unsigned long rc, void *regs, int num, int irq_disabl
//#define DEBUG_PRINT_SC //#define DEBUG_PRINT_SC
#ifdef DEBUG_PRINT_SC #ifdef DEBUG_PRINT_SC
#define dkprintf kprintf #undef DDEBUG_DEFAULT
#define ekprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0) #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#endif #endif
#define NOT_IMPLEMENTED() do { kprintf("%s is not implemented\n", __func__); while(1);} while(0) #define NOT_IMPLEMENTED() do { kprintf("%s is not implemented\n", __func__); while(1);} while(0)

View File

@@ -14,15 +14,13 @@
#include <ihk/debug.h> #include <ihk/debug.h>
#include <ikc/queue.h> #include <ikc/queue.h>
#include <vdso.h> #include <vdso.h>
#include <debug.h>
//#define DEBUG_PRINT_VDSO //#define DEBUG_PRINT_VDSO
#ifdef DEBUG_PRINT_VDSO #ifdef DEBUG_PRINT_VDSO
#define dkprintf(...) kprintf(__VA_ARGS__) #undef DDEBUG_DEFAULT
#define ekprintf(...) kprintf(__VA_ARGS__) #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf(...) kprintf(__VA_ARGS__)
#endif #endif
#ifdef POSTK_DEBUG_ARCH_DEP_52 #ifdef POSTK_DEBUG_ARCH_DEP_52

View File

@@ -9,29 +9,29 @@ PHDRS
SECTIONS SECTIONS
{ {
. = SIZEOF_HEADERS; . = SIZEOF_HEADERS;
. = ALIGN(4096); . = ALIGN(4096);
.text : { .text : {
*(.text) *(.text)
} :text } :text
.data : { .data : {
*(.data) *(.data)
*(.data.*) *(.data.*)
} :data } :data
.rodata : { .rodata : {
*(.rodata .rodata.*) *(.rodata .rodata.*)
} :data } :data
. = ALIGN(8); . = ALIGN(8);
.bss : { .bss : {
_bss_start = .; _bss_start = .;
*(.bss .bss.*) *(.bss .bss.*)
_bss_end = .; _bss_end = .;
. = ALIGN(4096); . = ALIGN(4096);
_stack_end = .; _stack_end = .;
} :data } :data
/DISCARD/ : { /DISCARD/ : {
*(.eh_frame) *(.eh_frame)
*(.note.gnu.build-id) *(.note.gnu.build-id)
} }
} }

View File

@@ -31,6 +31,7 @@
#include <prctl.h> #include <prctl.h>
#include <page.h> #include <page.h>
#include <kmalloc.h> #include <kmalloc.h>
#include <debug.h>
#define LAPIC_ID 0x020 #define LAPIC_ID 0x020
#define LAPIC_TIMER 0x320 #define LAPIC_TIMER 0x320
@@ -69,11 +70,8 @@
//#define DEBUG_PRINT_CPU //#define DEBUG_PRINT_CPU
#ifdef DEBUG_PRINT_CPU #ifdef DEBUG_PRINT_CPU
#define dkprintf kprintf #undef DDEBUG_DEFAULT
#define ekprintf kprintf #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf kprintf
#endif #endif
static void *lapic_vp; static void *lapic_vp;

View File

@@ -6,6 +6,7 @@
#include <process.h> #include <process.h>
#include <string.h> #include <string.h>
#include <elfcore.h> #include <elfcore.h>
#include <debug.h>
#define align32(x) ((((x) + 3) / 4) * 4) #define align32(x) ((((x) + 3) / 4) * 4)
#define alignpage(x) ((((x) + (PAGE_SIZE) - 1) / (PAGE_SIZE)) * (PAGE_SIZE)) #define alignpage(x) ((((x) + (PAGE_SIZE) - 1) / (PAGE_SIZE)) * (PAGE_SIZE))
@@ -13,11 +14,8 @@
//#define DEBUG_PRINT_GENCORE //#define DEBUG_PRINT_GENCORE
#ifdef DEBUG_PRINT_GENCORE #ifdef DEBUG_PRINT_GENCORE
#define dkprintf(...) kprintf(__VA_ARGS__) #undef DDEBUG_DEFAULT
#define ekprintf(...) kprintf(__VA_ARGS__) #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf(...) kprintf(__VA_ARGS__)
#endif #endif
/* /*

View File

@@ -25,15 +25,13 @@
#include <cls.h> #include <cls.h>
#include <kmalloc.h> #include <kmalloc.h>
#include <rusage_private.h> #include <rusage_private.h>
#include <debug.h>
//#define DEBUG //#define DEBUG
#ifdef DEBUG #ifdef DEBUG
#define dkprintf(...) do { kprintf(__VA_ARGS__); } while (0) #undef DDEBUG_DEFAULT
#define ekprintf(...) do { kprintf(__VA_ARGS__); } while (0) #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { } while (0)
#define ekprintf(...) do { kprintf(__VA_ARGS__); } while (0)
#endif #endif
static char *last_page; static char *last_page;

View File

@@ -16,6 +16,7 @@
#include <registers.h> #include <registers.h>
#include <mc_perf_event.h> #include <mc_perf_event.h>
#include <config.h> #include <config.h>
#include <debug.h>
extern unsigned int *x86_march_perfmap; extern unsigned int *x86_march_perfmap;
extern int running_on_kvm(void); extern int running_on_kvm(void);
@@ -25,11 +26,8 @@ int ihk_mc_perfctr_fixed_init(int counter, int mode);
//#define PERFCTR_DEBUG //#define PERFCTR_DEBUG
#ifdef PERFCTR_DEBUG #ifdef PERFCTR_DEBUG
#define dkprintf(...) do { kprintf(__VA_ARGS__); } while (0) #undef DDEBUG_DEFAULT
#define ekprintf(...) do { kprintf(__VA_ARGS__); } while (0) #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { } while (0)
#define ekprintf(...) do { kprintf(__VA_ARGS__); } while (0)
#endif #endif
#define X86_CR4_PCE 0x00000100 #define X86_CR4_PCE 0x00000100

View File

@@ -31,6 +31,7 @@
#include <page.h> #include <page.h>
#include <limits.h> #include <limits.h>
#include <syscall.h> #include <syscall.h>
#include <debug.h>
void terminate_mcexec(int, int); void terminate_mcexec(int, int);
extern long do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact); extern long do_sigaction(int sig, struct k_sigaction *act, struct k_sigaction *oact);
@@ -45,11 +46,8 @@ extern uint64_t get_xsave_mask();
//#define DEBUG_PRINT_SC //#define DEBUG_PRINT_SC
#ifdef DEBUG_PRINT_SC #ifdef DEBUG_PRINT_SC
#define dkprintf kprintf #undef DDEBUG_DEFAULT
#define ekprintf(...) kprintf(__VA_ARGS__) #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf(...) kprintf(__VA_ARGS__)
#endif #endif
uintptr_t debug_constants[] = { uintptr_t debug_constants[] = {

View File

@@ -29,15 +29,13 @@
#include <time.h> #include <time.h>
#include <syscall.h> #include <syscall.h>
#include <rusage_private.h> #include <rusage_private.h>
#include <debug.h>
//#define DEBUG_PRINT_AP //#define DEBUG_PRINT_AP
#ifdef DEBUG_PRINT_AP #ifdef DEBUG_PRINT_AP
#define dkprintf(...) do { kprintf(__VA_ARGS__); } while (0) #undef DDEBUG_DEFAULT
#define ekprintf(...) do { kprintf(__VA_ARGS__); } while (0) #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { } while (0)
#define ekprintf(...) do { kprintf(__VA_ARGS__); } while (0)
#endif #endif
int num_processors = 1; int num_processors = 1;

View File

@@ -1,24 +1,28 @@
PHDRS PHDRS
{ {
text PT_LOAD FLAGS(5); text PT_LOAD FLAGS(5);
data PT_LOAD FLAGS(7); data PT_LOAD FLAGS(7);
} }
SECTIONS SECTIONS
{ {
. = 0xffffffff80001000; . = 0xffffffff80001000;
_head = .; _head = .;
.text : { .text : {
*(.text); *(.text);
} : text } : text
. = ALIGN(4096); . = ALIGN(4096);
.data : { .data : {
*(.data) *(.data)
*(.data.*) *(.data.*)
. = ALIGN(8);
__start___verbose = .;
*(__verbose);
__stop___verbose = .;
} :data } :data
.rodata : { .rodata : {
*(.rodata .rodata.*) *(.rodata .rodata.*)
} :data } :data
.vsyscall : ALIGN(0x1000) { .vsyscall : ALIGN(0x1000) {
@@ -37,14 +41,14 @@ SECTIONS
. = ALIGN(4096); . = ALIGN(4096);
} : data = 0xf4 } : data = 0xf4
.bss : { .bss : {
*(.bss .bss.*) *(.bss .bss.*)
} }
. = ALIGN(4096); . = ALIGN(4096);
_end = .; _end = .;
/DISCARD/ : { /DISCARD/ : {
*(.eh_frame) *(.eh_frame)
*(.note.gnu.build-id) *(.note.gnu.build-id)
} }
} }

View File

@@ -1,24 +1,28 @@
PHDRS PHDRS
{ {
text PT_LOAD FLAGS(5); text PT_LOAD FLAGS(5);
data PT_LOAD FLAGS(7); data PT_LOAD FLAGS(7);
} }
SECTIONS SECTIONS
{ {
. = 0xffffffff80001000; . = 0xffffffff80001000;
_head = .; _head = .;
.text : { .text : {
*(.text); *(.text);
} : text } : text
. = ALIGN(4096); . = ALIGN(4096);
.data : { .data : {
*(.data) *(.data)
*(.data.*) *(.data.*)
. = ALIGN(8);
__start___verbose = .;
*(__verbose);
__stop___verbose = .;
} :data } :data
.rodata : { .rodata : {
*(.rodata .rodata.*) *(.rodata .rodata.*)
} :data } :data
.vsyscall : ALIGN(0x1000) { .vsyscall : ALIGN(0x1000) {
@@ -37,14 +41,14 @@ SECTIONS
. = ALIGN(4096); . = ALIGN(4096);
} : data = 0xf4 } : data = 0xf4
.bss : { .bss : {
*(.bss .bss.*) *(.bss .bss.*)
} }
. = ALIGN(4096); . = ALIGN(4096);
_end = .; _end = .;
/DISCARD/ : { /DISCARD/ : {
*(.eh_frame) *(.eh_frame)
*(.note.gnu.build-id) *(.note.gnu.build-id)
} }
} }

View File

@@ -1,24 +1,28 @@
PHDRS PHDRS
{ {
text PT_LOAD FLAGS(5); text PT_LOAD FLAGS(5);
data PT_LOAD FLAGS(7); data PT_LOAD FLAGS(7);
} }
SECTIONS SECTIONS
{ {
. = 0xffffffff80001000; . = 0xffffffff80001000;
_head = .; _head = .;
.text : { .text : {
*(.text); *(.text);
} : text } : text
. = ALIGN(4096); . = ALIGN(4096);
.data : { .data : {
*(.data) *(.data)
*(.data.*) *(.data.*)
. = ALIGN(8);
__start___verbose = .;
*(__verbose);
__stop___verbose = .;
} :data } :data
.rodata : { .rodata : {
*(.rodata .rodata.*) *(.rodata .rodata.*)
} :data } :data
.vsyscall : ALIGN(0x1000) { .vsyscall : ALIGN(0x1000) {
@@ -37,10 +41,10 @@ SECTIONS
. = ALIGN(4096); . = ALIGN(4096);
} : data = 0xf4 } : data = 0xf4
.bss : { .bss : {
*(.bss .bss.*) *(.bss .bss.*)
} }
. = ALIGN(4096); . = ALIGN(4096);
_end = .; _end = .;
} }

View File

@@ -16,6 +16,10 @@ SECTIONS
.data : { .data : {
*(.data) *(.data)
*(.data.*) *(.data.*)
. = ALIGN(8);
__start___verbose = .;
*(__verbose);
__stop___verbose = .;
} :data } :data
.rodata : { .rodata : {
*(.rodata .rodata.*) *(.rodata .rodata.*)

View File

@@ -16,6 +16,10 @@ SECTIONS
.data : { .data : {
*(.data) *(.data)
*(.data.*) *(.data.*)
. = ALIGN(8);
__start___verbose = .;
*(__verbose);
__stop___verbose = .;
} :data } :data
.rodata : { .rodata : {
*(.rodata .rodata.*) *(.rodata .rodata.*)

View File

@@ -16,6 +16,10 @@ SECTIONS
.data : { .data : {
*(.data) *(.data)
*(.data.*) *(.data.*)
. = ALIGN(8);
__start___verbose = .;
*(__verbose);
__stop___verbose = .;
} :data } :data
.rodata : { .rodata : {
*(.rodata .rodata.*) *(.rodata .rodata.*)

View File

@@ -16,6 +16,10 @@ SECTIONS
.data : { .data : {
*(.data) *(.data)
*(.data.*) *(.data.*)
. = ALIGN(8);
__start___verbose = .;
*(__verbose);
__stop___verbose = .;
} :data } :data
.rodata : { .rodata : {
*(.rodata .rodata.*) *(.rodata .rodata.*)

View File

@@ -1,24 +1,28 @@
PHDRS PHDRS
{ {
text PT_LOAD FLAGS(5); text PT_LOAD FLAGS(5);
data PT_LOAD FLAGS(7); data PT_LOAD FLAGS(7);
} }
SECTIONS SECTIONS
{ {
. = 0xffffffff80001000; . = 0xffffffff80001000;
_head = .; _head = .;
.text : { .text : {
*(.text); *(.text);
} : text } : text
. = ALIGN(4096); . = ALIGN(4096);
.data : { .data : {
*(.data) *(.data)
*(.data.*) *(.data.*)
. = ALIGN(8);
__start___verbose = .;
*(__verbose);
__stop___verbose = .;
} :data } :data
.rodata : { .rodata : {
*(.rodata .rodata.*) *(.rodata .rodata.*)
} :data } :data
.vsyscall : ALIGN(0x1000) { .vsyscall : ALIGN(0x1000) {
@@ -37,9 +41,9 @@ SECTIONS
. = ALIGN(4096); . = ALIGN(4096);
} : data = 0xf4 } : data = 0xf4
.bss : { .bss : {
*(.bss .bss.*) *(.bss .bss.*)
} }
. = ALIGN(4096); . = ALIGN(4096);
_end = .; _end = .;
} }

View File

@@ -18,6 +18,9 @@
#include <ihk/lock.h> #include <ihk/lock.h>
#include <ihk/monitor.h> #include <ihk/monitor.h>
#include <errno.h> #include <errno.h>
#include <sysfs.h>
#include <debug.h>
#include <limits.h>
struct ihk_kmsg_buf *kmsg_buf; struct ihk_kmsg_buf *kmsg_buf;
@@ -180,3 +183,147 @@ void kmsg_init()
{ {
ihk_mc_spinlock_init(&kmsg_lock); ihk_mc_spinlock_init(&kmsg_lock);
} }
extern struct ddebug __start___verbose[];
extern struct ddebug __stop___verbose[];
static ssize_t dynamic_debug_sysfs_show(struct sysfs_ops *ops,
void *instance, void *buf, size_t size)
{
struct ddebug *dbg;
ssize_t n = 0;
n = snprintf(buf, size, "# filename:lineno function flags format\n");
for (dbg = __start___verbose; dbg < __stop___verbose; dbg++) {
n += snprintf(buf + n, size - n, "%s:%d %s =%s\n",
dbg->file, dbg->line, dbg->func,
dbg->flags ? "p" : "_");
if (n >= size)
break;
}
return n;
}
static ssize_t dynamic_debug_sysfs_store(struct sysfs_ops *ops,
void *instance, void *buf, size_t size)
{
char *cur = buf;
char *file = NULL, *func = NULL;
long int line_start = 0, line_end = INT_MAX;
int set_flag = -1;
struct ddebug *dbg;
// assume line was new-line terminated and squash last newline
cur[size-1] = '\0';
/* basic line parsing, combinaisons of:
* file <file>
* func <func>
* line <line|line-line|line-|-line>
* and must end with [+-=][p_] (set/clear print flag)
*/
again:
while (cur && cur < ((char *)buf) + size && *cur) {
dkprintf("looking at %.*s, size left %d\n",
size - (cur - (char *)buf), cur,
(char *)buf - cur + size);
if (strncmp(cur, "func ", 5) == 0) {
cur += 5;
func = cur;
} else if (strncmp(cur, "file ", 5) == 0) {
cur += 5;
file = cur;
} else if (strncmp(cur, "line ", 5) == 0) {
cur += 5;
if (*cur != '-') {
line_start = strtol(cur, &cur, 0);
}
if (*cur != '-') {
line_end = line_start;
} else {
cur++;
if (*cur == ' ' || *cur == '\0') {
line_end = INT_MAX;
} else {
line_end = strtol(cur, &cur, 0);
}
}
} else if (strchr("+-=", *cur)) {
switch ((*cur) + 256 * (*(cur+1))) {
case '+' + 256*'p':
case '=' + 256*'p':
set_flag = DDEBUG_PRINT;
break;
case '-' + 256*'p':
case '=' + 256*'_':
set_flag = DDEBUG_NONE;
break;
default:
kprintf("invalid flag: %.*s\n",
size - (cur - (char *)buf), cur);
return -EINVAL;
}
/* XXX check 3rd char is end of input or \n or ; */
cur += 3;
break;
} else {
kprintf("dynamic debug control: unrecognized keyword: %.*s\n",
size - (cur - (char *)buf), cur);
return -EINVAL;
}
cur = strpbrk(cur, " \n");
if (cur) {
*cur = '\0';
cur++;
}
}
dkprintf("func %s, file %s, lines %d-%d, flag %x\n",
func, file, line_start, line_end, set_flag);
if (set_flag < 0) {
kprintf("dynamic debug control: no flag set?\n");
return -EINVAL;
}
if (!func && !file) {
kprintf("at least file or func should be set\n");
return -EINVAL;
}
for (dbg = __start___verbose; dbg < __stop___verbose; dbg++) {
/* TODO: handle wildcards */
if ((!func || strcmp(func, dbg->func) == 0) &&
(!file || strcmp(file, dbg->file) == 0) &&
dbg->line >= line_start &&
dbg->line <= line_end) {
dbg->flags = set_flag;
}
}
if (cur && cur < ((char *)buf) + size && *cur)
goto again;
return size;
}
static struct sysfs_ops dynamic_debug_sysfs_ops = {
.show = &dynamic_debug_sysfs_show,
.store = &dynamic_debug_sysfs_store,
};
void dynamic_debug_sysfs_setup(void)
{
int error;
error = sysfs_createf(&dynamic_debug_sysfs_ops, NULL, 0644,
"/sys/kernel/debug/dynamic_debug/control");
if (error) {
kprintf("%s: ERROR: creating dynamic_debug/control sysfs file",
__func__);
}
}

View File

@@ -36,15 +36,13 @@
#include <syscall.h> #include <syscall.h>
#include <process.h> #include <process.h>
#include <rusage_private.h> #include <rusage_private.h>
#include <debug.h>
//#define DEBUG_PRINT_DEVOBJ //#define DEBUG_PRINT_DEVOBJ
#ifdef DEBUG_PRINT_DEVOBJ #ifdef DEBUG_PRINT_DEVOBJ
#define dkprintf(...) kprintf(__VA_ARGS__) #undef DDEBUG_DEFAULT
#define ekprintf(...) kprintf(__VA_ARGS__) #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf(...) kprintf(__VA_ARGS__)
#endif #endif

View File

@@ -27,15 +27,13 @@
#include <string.h> #include <string.h>
#include <syscall.h> #include <syscall.h>
#include <rusage_private.h> #include <rusage_private.h>
#include <debug.h>
//#define DEBUG_PRINT_FILEOBJ //#define DEBUG_PRINT_FILEOBJ
#ifdef DEBUG_PRINT_FILEOBJ #ifdef DEBUG_PRINT_FILEOBJ
#define dkprintf(...) do { if (1) kprintf(__VA_ARGS__); } while (0) #undef DDEBUG_DEFAULT
#define ekprintf(...) kprintf(__VA_ARGS__) #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf(...) kprintf(__VA_ARGS__)
#endif #endif
mcs_lock_t fileobj_list_lock; mcs_lock_t fileobj_list_lock;

View File

@@ -70,13 +70,13 @@
#include <cls.h> #include <cls.h>
#include <kmsg.h> #include <kmsg.h>
#include <timer.h> #include <timer.h>
#include <debug.h>
//#define DEBUG_PRINT_FUTEX //#define DEBUG_PRINT_FUTEX
#ifdef DEBUG_PRINT_FUTEX #ifdef DEBUG_PRINT_FUTEX
#define dkprintf kprintf #undef DDEBUG_DEFAULT
#else #define DDEBUG_DEFAULT DDEBUG_PRINT
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#endif #endif
int futex_cmpxchg_enabled; int futex_cmpxchg_enabled;

View File

@@ -34,13 +34,13 @@
#include <sysfs.h> #include <sysfs.h>
#include <ihk/perfctr.h> #include <ihk/perfctr.h>
#include <rusage_private.h> #include <rusage_private.h>
#include <debug.h>
//#define DEBUG_PRINT_HOST //#define DEBUG_PRINT_HOST
#ifdef DEBUG_PRINT_HOST #ifdef DEBUG_PRINT_HOST
#define dkprintf kprintf #undef DDEBUG_DEFAULT
#else #define DDEBUG_DEFAULT DDEBUG_PRINT
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#endif #endif
/* Linux channel table, indexec by Linux CPU id */ /* Linux channel table, indexec by Linux CPU id */

40
kernel/include/debug.h Normal file
View File

@@ -0,0 +1,40 @@
#ifndef DEBUG_H
#define DEBUG_H
#include <lwk/compiler.h>
struct ddebug {
const char *file;
const char *func;
const char *fmt;
unsigned int line:24;
unsigned int flags:8;
} __aligned(8);
#define DDEBUG_NONE 0x0
#define DDEBUG_PRINT 0x1
#define DDEBUG_DEFAULT DDEBUG_NONE
#define DDEBUG_SYMBOL() \
static struct ddebug __aligned(8) \
__attribute__((section("__verbose"))) ddebug = { \
.file = __FILE__, \
.func = __func__, \
.line = __LINE__, \
.flags = DDEBUG_DEFAULT, \
}
#define DDEBUG_TEST ddebug.flags
#define dkprintf(fmt, args...) \
do { \
DDEBUG_SYMBOL(); \
if (DDEBUG_TEST) \
kprintf(fmt, ##args); \
} while (0)
#define ekprintf(fmt, args...) kprintf(fmt, ##args)
#endif

View File

@@ -33,6 +33,7 @@ extern void cpu_sysfs_setup(void);
extern void numa_sysfs_setup(void); extern void numa_sysfs_setup(void);
extern void rusage_sysfs_setup(void); extern void rusage_sysfs_setup(void);
extern void status_sysfs_setup(void); extern void status_sysfs_setup(void);
extern void dynamic_debug_sysfs_setup(void);
extern char *find_command_line(char *name); extern char *find_command_line(char *name);

View File

@@ -26,20 +26,17 @@
#include <mc_xpmem.h> #include <mc_xpmem.h>
#include <xpmem.h> #include <xpmem.h>
#include <debug.h>
#define XPMEM_CURRENT_VERSION 0x00026003 #define XPMEM_CURRENT_VERSION 0x00026003
//#define DEBUG_PRINT_XPMEM //#define DEBUG_PRINT_XPMEM
#ifdef DEBUG_PRINT_XPMEM #ifdef DEBUG_PRINT_XPMEM
#define dkprintf(...) kprintf(__VA_ARGS__) #undef DDEBUG_DEFAULT
#define ekprintf(...) kprintf(__VA_ARGS__) #define DDEBUG_DEFAULT DDEBUG_PRINT
#define XPMEM_DEBUG(format, a...) kprintf("[%d] %s: "format"\n", cpu_local_var(current)->proc->rgid, __func__, ##a)
#else
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf(...) kprintf(__VA_ARGS__)
#define XPMEM_DEBUG(format, a...) do { if (0) kprintf("\n"); } while (0)
#endif #endif
#define XPMEM_DEBUG(format, a...) dkprintf("[%d] %s: "format"\n", cpu_local_var(current)->proc->rgid, __func__, ##a)
//#define USE_DBUG_ON //#define USE_DBUG_ON

View File

@@ -32,6 +32,7 @@
#include <syscall.h> #include <syscall.h>
#include <sysfs.h> #include <sysfs.h>
#include <ihk/monitor.h> #include <ihk/monitor.h>
#include <debug.h>
//#define IOCTL_FUNC_EXTENSION //#define IOCTL_FUNC_EXTENSION
#ifdef IOCTL_FUNC_EXTENSION #ifdef IOCTL_FUNC_EXTENSION
@@ -41,11 +42,8 @@
//#define DEBUG_PRINT_INIT //#define DEBUG_PRINT_INIT
#ifdef DEBUG_PRINT_INIT #ifdef DEBUG_PRINT_INIT
#define dkprintf(...) do { kprintf(__VA_ARGS__); } while (0) #undef DDEBUG_DEFAULT
#define ekprintf(...) do { kprintf(__VA_ARGS__); } while (0) #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { } while (0)
#define ekprintf(...) do { kprintf(__VA_ARGS__); } while (0)
#endif #endif
#define DUMP_LEVEL_USER_UNUSED_EXCLUDE 24 #define DUMP_LEVEL_USER_UNUSED_EXCLUDE 24
@@ -331,6 +329,7 @@ static void populate_sysfs(void)
{ {
cpu_sysfs_setup(); cpu_sysfs_setup();
numa_sysfs_setup(); numa_sysfs_setup();
dynamic_debug_sysfs_setup();
//setup_remote_snooping_samples(); //setup_remote_snooping_samples();
} /* populate_sysfs() */ } /* populate_sysfs() */

View File

@@ -19,15 +19,13 @@
#include <ihk/ikc.h> #include <ihk/ikc.h>
#include <ikc/master.h> #include <ikc/master.h>
#include <arch/cpu.h> #include <arch/cpu.h>
#include <debug.h>
//#define DEBUG_LISTENERS //#define DEBUG_LISTENERS
#ifdef DEBUG_LISTENERS #ifdef DEBUG_LISTENERS
#define dkprintf(...) kprintf(__VA_ARGS__) #undef DDEBUG_DEFAULT
#define ekprintf(...) kprintf(__VA_ARGS__) #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf(...) kprintf(__VA_ARGS__)
#endif #endif
void testmem(void *v, unsigned long size) void testmem(void *v, unsigned long size)

View File

@@ -44,15 +44,13 @@
#include <process.h> #include <process.h>
#include <limits.h> #include <limits.h>
#include <sysfs.h> #include <sysfs.h>
#include <debug.h>
//#define DEBUG_PRINT_MEM //#define DEBUG_PRINT_MEM
#ifdef DEBUG_PRINT_MEM #ifdef DEBUG_PRINT_MEM
#define dkprintf(...) kprintf(__VA_ARGS__) #undef DDEBUG_DEFAULT
#define ekprintf(...) kprintf(__VA_ARGS__) #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf(...) kprintf(__VA_ARGS__)
#endif #endif
static unsigned long pa_start, pa_end; static unsigned long pa_start, pa_end;

View File

@@ -21,6 +21,7 @@
#include <kmalloc.h> #include <kmalloc.h>
#include <process.h> #include <process.h>
#include <swapfmt.h> #include <swapfmt.h>
#include <debug.h>
#define O_RDONLY 00000000 #define O_RDONLY 00000000
#define O_WRONLY 00000001 #define O_WRONLY 00000001
@@ -44,11 +45,8 @@
//#define DEBUG_PRINT_PROCESS //#define DEBUG_PRINT_PROCESS
#ifdef DEBUG_PRINT_PROCESS #ifdef DEBUG_PRINT_PROCESS
#define dkprintf(...) kprintf(__VA_ARGS__) #undef DDEBUG_DEFAULT
#define ekprintf(...) kprintf(__VA_ARGS__) #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf(...) kprintf(__VA_ARGS__)
#endif #endif
/* /*

View File

@@ -38,12 +38,13 @@
#include <xpmem.h> #include <xpmem.h>
#include <rusage_private.h> #include <rusage_private.h>
#include <ihk/monitor.h> #include <ihk/monitor.h>
#include <debug.h>
//#define DEBUG_PRINT_PROCESS //#define DEBUG_PRINT_PROCESS
#ifdef DEBUG_PRINT_PROCESS #ifdef DEBUG_PRINT_PROCESS
#define dkprintf(...) kprintf(__VA_ARGS__) #undef DDEBUG_DEFAULT
#define ekprintf(...) kprintf(__VA_ARGS__) #define DDEBUG_DEFAULT DDEBUG_PRINT
static void dtree(struct rb_node *node, int l) { static void dtree(struct rb_node *node, int l) {
struct vm_range *range; struct vm_range *range;
if (!node) if (!node)
@@ -60,8 +61,6 @@ static void dump_tree(struct process_vm *vm) {
dtree(vm->vm_range_tree.rb_node, 1); dtree(vm->vm_range_tree.rb_node, 1);
} }
#else #else
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf(...) kprintf(__VA_ARGS__)
static void dump_tree(struct process_vm *vm) {} static void dump_tree(struct process_vm *vm) {}
#endif #endif

View File

@@ -39,6 +39,7 @@
#include <limits.h> #include <limits.h>
#include <march.h> #include <march.h>
#include <process.h> #include <process.h>
#include <debug.h>
extern char *syscall_name[]; extern char *syscall_name[];
@@ -47,11 +48,8 @@ extern char *syscall_name[];
//#define DEBUG_PRINT_PROFILE //#define DEBUG_PRINT_PROFILE
#ifdef DEBUG_PRINT_PROFILE #ifdef DEBUG_PRINT_PROFILE
#define dkprintf(...) kprintf(__VA_ARGS__) #undef DDEBUG_DEFAULT
#define ekprintf(...) kprintf(__VA_ARGS__) #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf(...) kprintf(__VA_ARGS__)
#endif #endif

View File

@@ -23,10 +23,8 @@
#include <shm.h> #include <shm.h>
#include <string.h> #include <string.h>
#include <rusage_private.h> #include <rusage_private.h>
#include <debug.h>
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf(...) kprintf(__VA_ARGS__)
#define fkprintf(...) kprintf(__VA_ARGS__)
static LIST_HEAD(shmobj_list_head); static LIST_HEAD(shmobj_list_head);
static ihk_spinlock_t shmobj_list_lock_body = SPIN_LOCK_UNLOCKED; static ihk_spinlock_t shmobj_list_lock_body = SPIN_LOCK_UNLOCKED;
@@ -273,7 +271,7 @@ void shmobj_destroy(struct shmobj *obj)
page->mode, page->count); page->mode, page->count);
count = ihk_atomic_sub_return(1, &page->count); count = ihk_atomic_sub_return(1, &page->count);
if (!((page->mode == PM_MAPPED) && (count == 0))) { if (!((page->mode == PM_MAPPED) && (count == 0))) {
fkprintf("shmobj_destroy(%p): " ekprintf("shmobj_destroy(%p): "
"page %p phys %#lx mode %#x" "page %p phys %#lx mode %#x"
" count %d off %#lx\n", " count %d off %#lx\n",
obj, page, obj, page,
@@ -335,7 +333,7 @@ static void shmobj_release(struct memobj *memobj)
newref = --obj->ds.shm_nattch; newref = --obj->ds.shm_nattch;
if (newref <= 0) { if (newref <= 0) {
if (newref < 0) { if (newref < 0) {
fkprintf("shmobj_release(%p):ref %ld\n", ekprintf("shmobj_release(%p):ref %ld\n",
memobj, newref); memobj, newref);
panic("shmobj_release:freeing free shmobj"); panic("shmobj_release:freeing free shmobj");
} }
@@ -430,7 +428,7 @@ static int shmobj_get_page(struct memobj *memobj, off_t off, int p2align,
Add when setting the PTE for a page with count of one in ihk_mc_pt_set_range(). */ Add when setting the PTE for a page with count of one in ihk_mc_pt_set_range(). */
if (page->mode != PM_NONE) { if (page->mode != PM_NONE) {
fkprintf("shmobj_get_page(%p,%#lx,%d,%p):" ekprintf("shmobj_get_page(%p,%#lx,%d,%p):"
"page %p %#lx %d %d %#lx\n", "page %p %#lx %d %d %#lx\n",
memobj, off, p2align, physp, memobj, off, p2align, physp,
page, page_to_phys(page), page->mode, page, page_to_phys(page), page->mode,

View File

@@ -59,6 +59,7 @@
#include <rusage_private.h> #include <rusage_private.h>
#include <ihk/monitor.h> #include <ihk/monitor.h>
#include <profile.h> #include <profile.h>
#include <debug.h>
/* Headers taken from kitten LWK */ /* Headers taken from kitten LWK */
#include <lwk/stddef.h> #include <lwk/stddef.h>
@@ -69,11 +70,8 @@
//#define DEBUG_PRINT_SC //#define DEBUG_PRINT_SC
#ifdef DEBUG_PRINT_SC #ifdef DEBUG_PRINT_SC
#define dkprintf(...) kprintf(__VA_ARGS__) #undef DDEBUG_DEFAULT
#define ekprintf(...) kprintf(__VA_ARGS__) #define DDEBUG_DEFAULT DDEBUG_PRINT
#else
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf(...) kprintf(__VA_ARGS__)
#endif #endif
//static ihk_atomic_t pid_cnt = IHK_ATOMIC_INIT(1024); //static ihk_atomic_t pid_cnt = IHK_ATOMIC_INIT(1024);

View File

@@ -23,9 +23,7 @@
#include <sysfs.h> #include <sysfs.h>
#include <sysfs_msg.h> #include <sysfs_msg.h>
#include <vsprintf.h> #include <vsprintf.h>
#include <debug.h>
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf(...) do { if (1) kprintf(__VA_ARGS__); } while (0)
static size_t sysfs_data_bufsize; static size_t sysfs_data_bufsize;
static void *sysfs_data_buf; static void *sysfs_data_buf;

View File

@@ -32,13 +32,13 @@
#include <futex.h> #include <futex.h>
#include <bitops.h> #include <bitops.h>
#include <timer.h> #include <timer.h>
#include <debug.h>
//#define DEBUG_PRINT_TIMER //#define DEBUG_PRINT_TIMER
#ifdef DEBUG_PRINT_TIMER #ifdef DEBUG_PRINT_TIMER
#define dkprintf kprintf #undef DDEBUG_DEFAULT
#else #define DDEBUG_DEFAULT DDEBUG_PRINT
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#endif #endif
#define LOOP_TIMEOUT 500 #define LOOP_TIMEOUT 500

View File

@@ -283,7 +283,8 @@ static int xpmem_close(
int n_opened; int n_opened;
XPMEM_DEBUG("call: fd=%d, pid=%d, rgid=%d", XPMEM_DEBUG("call: fd=%d, pid=%d, rgid=%d",
mckfd->fd, proc->pid, proc->rgid); mckfd->fd, cpu_local_var(current)->proc->pid,
cpu_local_var(current)->proc->rgid);
n_opened = ihk_atomic_dec_return(&xpmem_my_part->n_opened); n_opened = ihk_atomic_dec_return(&xpmem_my_part->n_opened);
XPMEM_DEBUG("n_opened=%d", n_opened); XPMEM_DEBUG("n_opened=%d", n_opened);

View File

@@ -21,10 +21,7 @@
#include <memory.h> #include <memory.h>
#include <page.h> #include <page.h>
#include <string.h> #include <string.h>
#include <debug.h>
#define dkprintf(...) do { if (0) kprintf(__VA_ARGS__); } while (0)
#define ekprintf(...) kprintf(__VA_ARGS__)
#define fkprintf(...) kprintf(__VA_ARGS__)
struct zeroobj { struct zeroobj {
struct memobj memobj; /* must be first */ struct memobj memobj; /* must be first */
@@ -117,7 +114,7 @@ static int alloc_zeroobj(void)
page = phys_to_page_insert_hash(phys); page = phys_to_page_insert_hash(phys);
if (page->mode != PM_NONE) { if (page->mode != PM_NONE) {
fkprintf("alloc_zeroobj():" ekprintf("alloc_zeroobj():"
"page %p %#lx %d %d %#lx\n", "page %p %#lx %d %d %#lx\n",
page, page_to_phys(page), page->mode, page, page_to_phys(page), page->mode,
page->count, page->offset); page->count, page->offset);

View File

@@ -23,6 +23,7 @@ char *strncpy(char *dest, const char *src, size_t maxlen);
int strcmp(const char *s1, const char *s2); int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n); int strncmp(const char *s1, const char *s2, size_t n);
char *strstr(const char *haystack, const char *needle); char *strstr(const char *haystack, const char *needle);
char *strpbrk(const char *haystack, const char *accept);
char *strchr(const char *s, int n); char *strchr(const char *s, int n);
char *strrchr(const char *s, int n); char *strrchr(const char *s, int n);
void *memcpy(void *dest, const void *src, size_t n); void *memcpy(void *dest, const void *src, size_t n);

View File

@@ -112,6 +112,19 @@ strrchr(const char *s, int c)
return (char *)last; return (char *)last;
} /* strrchr() */ } /* strrchr() */
char *strpbrk(const char *s, const char *accept)
{
const char *a;
do {
for (a = accept; *a; a++)
if (*s == *a)
return (char *)s;
} while (*(s++));
return NULL;
}
char *strstr(const char *haystack, const char *needle) char *strstr(const char *haystack, const char *needle)
{ {
int len = strlen(needle); int len = strlen(needle);