fix: ajout de fonction de debogueuage et exception 1
This commit is contained in:
parent
bb21e15dc4
commit
109738dca3
|
@ -35,3 +35,18 @@
|
|||
return; \
|
||||
}
|
||||
|
||||
|
||||
#define DBG_EXEC 0b00
|
||||
#define DBG_WRITE 0b01
|
||||
#define DBG_CLEAR 0b10
|
||||
#define DBG_READWRITE 0b11
|
||||
|
||||
#define DBG_ONEBYTE 0b00
|
||||
#define DBG_TWOBYTE 0b01
|
||||
#define DBG_FOURBYTE 0b11
|
||||
|
||||
|
||||
void setdebugreg(u8 number,u8 *address, u8 type);
|
||||
u8* getdebugreg(u8 number);
|
||||
u32 disas(u8 *a);
|
||||
u32 decode(bool at, u8 *a, bool show);
|
||||
|
|
|
@ -21,3 +21,6 @@ int err();
|
|||
int view();
|
||||
int test(void);
|
||||
int disasm(u8* commandline);
|
||||
int bpset(u8* commandline);
|
||||
int bpclr(u8* commandline);
|
||||
int help();
|
||||
|
|
69
lib/cpu.c
69
lib/cpu.c
|
@ -206,6 +206,71 @@ asm(" addl %[size],%%esp \n \
|
|||
/******************************************************************************/
|
||||
/* Affiche les registres CPU */
|
||||
|
||||
void show_lightcpu(save_stack *stack)
|
||||
{
|
||||
u32 i;
|
||||
printf("\33[0mEAX=%Y EBX=%Y ECX=%Y EDX=%Y\r\n", stack->eax, stack->ebx, stack->ecx, stack->edx);
|
||||
printf("ESI=%Y EDI=%Y ESP=%Y EBP=%Y\r\n", stack->esi, stack->edi, stack->esp, stack->ebp);
|
||||
printf("EIP=%Y EFL=%Y [%c%c%c%c%c%c%c%c%c]\r\n", stack->eip, stack->eflags,
|
||||
(stack->eflags & (1 <<11)) ? 'O':'-',
|
||||
(stack->eflags & (1 <<10)) ? 'D':'-',
|
||||
(stack->eflags & (1 << 9)) ? 'I':'-',
|
||||
(stack->eflags & (1 << 8)) ? 'T':'-',
|
||||
(stack->eflags & (1 << 7)) ? 'S':'-',
|
||||
(stack->eflags & (1 << 6)) ? 'Z':'-',
|
||||
(stack->eflags & (1 << 4)) ? 'A':'-',
|
||||
(stack->eflags & (1 << 2)) ? 'P':'-',
|
||||
(stack->eflags & (1 << 0)) ? 'C':'-');
|
||||
printf("CS =%hY DS =%hY SS =%hY ES =%hY FS =%hY GS =%hY\r\n",stack->cs,stack->ds,stack->ss,stack->es,stack->fs,stack->gs);
|
||||
printf("CR0=%Y CR2=%Y CR3=%Y CR4=%Y\r\n\r\n\r\n",stack->cr0,stack->cr2,stack->cr3,stack->cr4);
|
||||
|
||||
u8* size;
|
||||
u8* pointer;
|
||||
for(i=20;i<50;i++) {
|
||||
pointer=stack->eip-i;
|
||||
size=pointer;
|
||||
size+=50;
|
||||
while(pointer<size) {
|
||||
pointer+=decode(false, pointer,false);
|
||||
if (pointer==stack->eip) break;
|
||||
}
|
||||
if (pointer==stack->eip) break;
|
||||
}
|
||||
if (pointer==stack->eip)
|
||||
pointer=stack->eip-i;
|
||||
else
|
||||
pointer=stack->eip;
|
||||
size=pointer;
|
||||
size+=50;
|
||||
while(pointer<size)
|
||||
{
|
||||
if (pointer==stack->eip)
|
||||
print("\33[41m\33[1m");
|
||||
else
|
||||
print("\33[40m\33[0m");
|
||||
pointer+=disas(pointer);
|
||||
}
|
||||
|
||||
printf("\33[0m\r\n\r\n\r\nSTACK\r\n");
|
||||
if (abs(KERNEL_STACK_ADDR-stack->esp)>0x10000)
|
||||
printf("Pile invalide !");
|
||||
else
|
||||
{
|
||||
i=0;
|
||||
for (u32 *pointer = stack->esp; pointer < KERNEL_STACK_ADDR; pointer ++) {
|
||||
if (i>0 && i % 10 == 0) print("\033[10A");
|
||||
if (i>=10)
|
||||
print("\033[25C");
|
||||
printf("+%d:%Y - %Y\r\n", i++, pointer, (u32)(*pointer));
|
||||
}
|
||||
for(u32 j=0;j<10-(i % 10);j++)
|
||||
print("\033[01B");
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* Affiche les registres CPU */
|
||||
|
||||
void show_cpu(save_stack *stack)
|
||||
{
|
||||
printf("EAX=%Y EBX=%Y ECX=%Y EDX=%Y\r\n", stack->eax, stack->ebx, stack->ecx, stack->edx);
|
||||
|
@ -250,10 +315,6 @@ void show_cpu(save_stack *stack)
|
|||
if (i>=10)
|
||||
print("\033[25C");
|
||||
printf("+%d:%Y - %Y\r\n", i++, pointer, (u32)(*pointer));
|
||||
if (i > 20) {
|
||||
print("...\r\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
for(u32 j=0;j<10-(i % 10);j++)
|
||||
print("\033[01B");
|
||||
|
|
768
lib/debug.c
768
lib/debug.c
File diff suppressed because it is too large
Load Diff
|
@ -8,6 +8,7 @@
|
|||
#include "video.h"
|
||||
#include "gdt.h"
|
||||
#include "system.h"
|
||||
#include "debug.h"
|
||||
|
||||
#define IDT_SIZE 256 /* nombre de descripteurs */
|
||||
|
||||
|
@ -188,7 +189,13 @@ void exception1()
|
|||
dump.eip=current->eip;
|
||||
dump.cs=current->cs;
|
||||
dump.esp=(current+1);
|
||||
cpuerror("#DB Debug exception",&dump);
|
||||
changevc(6);
|
||||
clearscreen();
|
||||
show_lightcpu(&dump);
|
||||
setdebugreg(0,0, DBG_CLEAR);
|
||||
sti();
|
||||
waitascii();
|
||||
iret();
|
||||
}
|
||||
|
||||
void exception2()
|
||||
|
|
86
lib/shell.c
86
lib/shell.c
|
@ -27,7 +27,10 @@ static command commands[] = {
|
|||
{"err" , "", &err},
|
||||
{"test" , "", &test},
|
||||
{"view" , "", &view},
|
||||
{"disasm" , "", &disasm}
|
||||
{"disasm" , "", &disasm},
|
||||
{"bpset" , "", &bpset},
|
||||
{"bpclr" , "", &bpclr},
|
||||
{"help" , "", &help},
|
||||
};
|
||||
|
||||
/*******************************************************************************/
|
||||
|
@ -49,7 +52,7 @@ void shell()
|
|||
strgetitem(&field, &item, ' ', 0);
|
||||
strtolower(&item);
|
||||
found = false;
|
||||
for (i = 0; i < sizeof(commands); i++) {
|
||||
for (i = 0; i < sizeof(commands)/sizeof(commands[0]); i++) {
|
||||
if (strcmp(&item, &commands[i].name) == 0) {
|
||||
(*commands[i].function) (&field);
|
||||
found = true;
|
||||
|
@ -64,6 +67,75 @@ void shell()
|
|||
int test(void)
|
||||
{
|
||||
print("Fonction de test !\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Renvoie les commandes disponibles */
|
||||
|
||||
int help()
|
||||
{
|
||||
print("Commandes disponibles :\r\n\r\n");
|
||||
for(u32 i=0;i<sizeof(commands)/sizeof(commands[0]);i++) {
|
||||
printf("%s \r\n",&commands[i].name);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/*******************************************************************************/
|
||||
/* Met un breakpoint */
|
||||
|
||||
int bpset(u8* commandline)
|
||||
{
|
||||
u8 arg[] = " \000";
|
||||
u8* numero;
|
||||
u8* pointer;
|
||||
u8 type=DBG_EXEC;
|
||||
if (strgetnbitems(commandline, ' ') < 3)
|
||||
{
|
||||
print("Syntaxe de la commande BPSET\r\nbpset \33[32mnumero address [type]\r\n\r\n \33[32mnumero\33[0m\33[0m\33[25D\33[10C - numero du breakpoint (0-3)\r\n \33[32madresse\33[0m\33[25D\33[10C - adresse du breakpoint\r\n \33[32mtype\33[0m\33[25D\33[10C - type de breakpoint (0-3)\r\n");
|
||||
return;
|
||||
}
|
||||
strgetitem(commandline, &arg, ' ', 1);
|
||||
numero=strtoint(&arg);
|
||||
if (numero>3) {
|
||||
print("numero incorrect");
|
||||
return;
|
||||
}
|
||||
strgetitem(commandline, &arg, ' ', 2);
|
||||
pointer=strtoint(&arg);
|
||||
if (strgetnbitems(commandline, ' ') == 4)
|
||||
{
|
||||
strgetitem(commandline, &arg, ' ', 3);
|
||||
type=strtoint(&arg);
|
||||
}
|
||||
if (type>DBG_READWRITE)
|
||||
{
|
||||
print("type incorrect");
|
||||
return;
|
||||
}
|
||||
setdebugreg(numero,pointer,type);
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
/* Retire un breakpoint */
|
||||
|
||||
int bpclr(u8* commandline)
|
||||
{
|
||||
u8 arg[] = " \000";
|
||||
u8* numero;
|
||||
|
||||
if (strgetnbitems(commandline, ' ') < 2)
|
||||
{
|
||||
print("Syntaxe de la commande BPCLR\r\nbpclr \33[32mnumero\r\n\r\n \33[32mnumero\33[0m\33[0m\33[25D\33[10C - numero du breakpoint (0-3)\r\n");
|
||||
return;
|
||||
}
|
||||
strgetitem(commandline, &arg, ' ', 1);
|
||||
numero=strtoint(&arg);
|
||||
if (numero>3) {
|
||||
print("numero incorrect");
|
||||
return;
|
||||
}
|
||||
setdebugreg(numero,0x0,DBG_CLEAR);
|
||||
}
|
||||
|
||||
/*******************************************************************************/
|
||||
|
@ -81,12 +153,13 @@ int disasm(u8* commandline)
|
|||
return;
|
||||
}
|
||||
strgetitem(commandline, &arg, ' ', 1);
|
||||
size=pointer=strtoint(&arg);
|
||||
pointer=strtoint(&arg);
|
||||
size=pointer;
|
||||
strgetitem(commandline, &arg, ' ', 2);
|
||||
size+=strtoint(&arg);
|
||||
while(pointer<size)
|
||||
{
|
||||
pointer+=decode(pointer);
|
||||
pointer+=disas(pointer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,9 +261,8 @@ int err(u8* commandline)
|
|||
break;
|
||||
case 1:
|
||||
print("Creation d'un breakpoint !\r\n");
|
||||
asm("movl %[address],%%dr0 \n \
|
||||
movl $0x00000003, %%eax\n \
|
||||
movl %%eax, %%dr7"::[address] "a" (&test):);
|
||||
setdebugreg(0,&test, DBG_EXEC);
|
||||
test();
|
||||
break;
|
||||
case 2:
|
||||
print("NON GERE!\r\n");
|
||||
|
|
|
@ -326,7 +326,7 @@ u32 storestr(u8* src, u8** dest, u32 len) {
|
|||
return len;
|
||||
}
|
||||
|
||||
#define maxbuffersize 1024
|
||||
#define maxbuffersize 4096
|
||||
|
||||
/*******************************************************************************/
|
||||
/* affiche une chaine de caractère formaté a l'ecran */
|
||||
|
|
Loading…
Reference in New Issue