Page 2 of 3

Re: File system hangs.

Posted: Tue Jun 03, 2025 12:32 pm
by iansjack
There are visual front ends to gdb. ddd is pretty good. It looks old fashioned but it can give you a better view into your program than VSCode or Eclipse. It’s often best to compile with optimizations disabled when debugging. Of course things are a bit tricky if enabling optimisation brings to light fresh bugs. Using objdump to provide a complete assembler listing of your program is also a great help.

As I said before, debugging is pretty much the same whatever language you use (although maybe superficially different for languages like Prolog, Lisp, or Smalltalk +p- not mainstream languages for OS development). It’s a question of being methodical and inspecting the machine state at appropriate points. It also helps to RTFM so that you know what any error codes signify.

I think most of my gripes with this thread could be solved by reading the forum rules, most specifically https://wiki.osdev.org/Getting_Started# ... _Knowledge and http://www.catb.org/~esr/faqs/smart-questions.html .

Re: File system hangs.

Posted: Tue Jun 03, 2025 12:35 pm
by zevvi
Thanks :D

Re: File system hangs.

Posted: Tue Jun 03, 2025 12:57 pm
by zevvi
Ok i tried the tools learned some more about gdb & ddd :D and figured out that the return address probably gets thrown off :arrow: the stack (overflown probably) atleast from what i can gather by looking at the stack :shock: . Because after the return statement it tries returning to 0x000000 #-o but ofcourse there is no code there so it just hangs. But im stuck there so i would like some more help please [-o< !

Re: File system hangs.

Posted: Tue Jun 03, 2025 1:43 pm
by nullplan
I already told you to look at the function you already identified. How big is the variable it declares, and how much do you write to it?

Re: File system hangs.

Posted: Wed Jun 04, 2025 3:06 am
by zevvi
Sorry didnt see your post haha πŸ˜…

Code: Select all

(gdb) target remote 127.0.0.1:1234
Remote debugging using 127.0.0.1:1234
0x0000fff0 in ?? ()
(gdb) break fs_init
Breakpoint 1 at 0x200560: file src/fs/fs.c, line 13.
(gdb) ptype fs_root
type = struct {
    char name[32];
    uint32_t start_address;
    uint32_t end_address;
    uint8_t used;
} [256]
(gdb) print sizeof(fs_root)
$1 = 10496
(gdb) c
Breakpoint 1, fs_init () at src/fs/fs.c:13
13          char signature[6] = {0};
(gdb) dump binary memory fs_before.dump fs_root fs_root+10496
(gdb) c
Continuing.
^C
Program received signal SIGINT, Interrupt.
0x53fb5491 in ?? ()
(gdb) dump binary memory fs_after.dump fs_root fs_root+10496
(gdb) exit

Code: Select all

cmp -l fs_before.dump fs_after.dump | tail
 10505   0   3
so it writes 9 bytes over the limit of fs_root
but using gdb watches never catches it?

Re: File system hangs.

Posted: Wed Jun 04, 2025 3:14 am
by zevvi
sebihepp wrote: ↑Tue Jun 03, 2025 12:04 pm
Octocontrabass wrote: ↑Tue Jun 03, 2025 9:25 am
zevvi wrote: ↑Tue Jun 03, 2025 2:26 amWell we ere talking about gdt and (of course) that doesnt exist in rust.
Which debugger do you use for Rust?
I think he is used to GUI-debuggers.
i Actually didnt i just used logging and debug statements and tests
(sorry i didnt mean gdt i meant gdb and i didnt know that was used for rust never heard of it)

Re: File system hangs.

Posted: Wed Jun 04, 2025 6:04 am
by sebihepp
Have a look at these lines of code:

Code: Select all

void fs_init() {
    char signature[6] = {0};
    ata_read_sectors(FS_SECTOR, 1, signature);
    (...)

Re: File system hangs.

Posted: Wed Jun 04, 2025 7:52 am
by zevvi
sebihepp wrote: ↑Wed Jun 04, 2025 6:04 am Have a look at these lines of code:

Code: Select all

void fs_init() {
    char signature[6] = {0};
    ata_read_sectors(FS_SECTOR, 1, signature);
    (...)
:?:

Re: File system hangs.

Posted: Wed Jun 04, 2025 8:08 am
by zevvi
zevvi wrote: ↑Wed Jun 04, 2025 7:52 am
sebihepp wrote: ↑Wed Jun 04, 2025 6:04 am Have a look at these lines of code:

Code: Select all

void fs_init() {
    char signature[6] = {0};
    ata_read_sectors(FS_SECTOR, 1, signature);
    (...)
I dont see anything wrong?

Re: File system hangs.

Posted: Wed Jun 04, 2025 8:18 am
by sebihepp
zevvi wrote: ↑Wed Jun 04, 2025 8:08 am
zevvi wrote: ↑Wed Jun 04, 2025 7:52 am
sebihepp wrote: ↑Wed Jun 04, 2025 6:04 am Have a look at these lines of code:

Code: Select all

void fs_init() {
    char signature[6] = {0};
    ata_read_sectors(FS_SECTOR, 1, signature);
    (...)
I dont see anything wrong?
How many bytes does ata_read_sectors() read? And how big is the variable signature?

Re: File system hangs.

Posted: Wed Jun 04, 2025 9:54 am
by zevvi
sebihepp wrote: ↑Wed Jun 04, 2025 8:18 am
zevvi wrote: ↑Wed Jun 04, 2025 8:08 am
zevvi wrote: ↑Wed Jun 04, 2025 7:52 am
I dont see anything wrong?
How many bytes does ata_read_sectors() read? And how big is the variable signature?

Code: Select all

(gdb) print sizeof(signature)
$1 = 6
(gdb)
(correct :mrgreen:)

and ata_lba_read reads 512 bytes πŸ˜… (overflow could corrupt memory)
fix:

Code: Select all

    unsigned char temp[512] = {0};
    char signature[6] = {0};
    ata_read_sectors(FS_SECTOR, 1, temp);
    memcpy(signature, temp, 6);
sadly enough that doesnt fix the hang after

Code: Select all

Done reading fs sectors...

Re: File system hangs.

Posted: Wed Jun 04, 2025 10:34 am
by sebihepp
You can simply do this:

Code: Select all

void fs_init() {
    char temp[512] = {0};
    ata_read_sectors(FS_SECTOR, 1, temp);
    terminal_writestring("Checking signature...\n");
    if (strncmp(temp, FS_SIGNATURE, 5) == 0) {
Next, I am not sure why you add 511 to sizeof(fs_root)?

Code: Select all

ata_read_sectors(FS_SECTOR + 1, (sizeof(fs_root) + 511) / 512, fs_root);
Why not just divide by 512? What is you train of thought?

I am also not sure what filesystem you use... did you develop your own?

Re: File system hangs.

Posted: Wed Jun 04, 2025 10:59 am
by zevvi
sebihepp wrote: ↑Wed Jun 04, 2025 10:34 am You can simply do this:

Code: Select all

void fs_init() {
    char temp[512] = {0};
    ata_read_sectors(FS_SECTOR, 1, temp);
    terminal_writestring("Checking signature...\n");
    if (strncmp(temp, FS_SIGNATURE, 5) == 0) {
thanks :P :!:
sebihepp wrote: ↑Wed Jun 04, 2025 10:34 am Next, I am not sure why you add 511 to sizeof(fs_root)?

Code: Select all

ata_read_sectors(FS_SECTOR + 1, (sizeof(fs_root) + 511) / 512, fs_root);
Why not just divide by 512? What is you train of thought?
yeah dont know late at night programming.
sebihepp wrote: ↑Wed Jun 04, 2025 10:34 am I am also not sure what filesystem you use... did you develop your own?
yes very simple just:

Code: Select all

typedef struct __attribute__((packed)) {
    char name[FS_NAME_MAX];
    uint32_t start_address;
    uint32_t end_address;
    uint8_t used;
} fs_entry_t;

static fs_entry_t fs_root[FS_MAX_ENTRIES];
thats all.

Re: File system hangs.

Posted: Thu Jun 05, 2025 5:03 am
by zevvi
I still cant figure it out :(

Re: File system hangs.

Posted: Thu Jun 05, 2025 6:47 am
by sebihepp
Did you removed that "+ 511"?