Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infra: creating the scripts folder #322

Merged
merged 1 commit into from
Jun 13, 2019
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
3 changes: 3 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Content

This folder should only contain tools and utilities not essential to the compilation of SunriseOS, but which can help its debugging and development.
18 changes: 18 additions & 0 deletions scripts/gdb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### Content

This folder contains gdb scripts and configurations, to help you keep your sanity during debugging sessions.

##### gdbinit

This template gdbinit is provided as an example.

You shouldn't use or modify it directly, but rather copy it to the root of this project, where it will be ignored by git and make any modifications you want there.
That way everyone can keep their own custom version without being harassed by git.

For it to be used by gdb when you start it, make sure to add this line to your `~/.gdbinit`:

```shell
$ cat ~/.gdbinit
#authorize running the .gdbinit in some folders
add-auto-load-safe-path <path to sunrise>/.gdbinit
```
46 changes: 46 additions & 0 deletions scripts/gdb/break_userspace.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import gdb

class UserspaceBreakpoint(gdb.Breakpoint):
"""Breakpoint breaking only in the right sunrise executable

Breakpoint that breaks only if we're in the right userspace executable, since all .text are loaded at the same address.

It uses the name found in the kernel current ProcessStruct and compares it with the module we're debugging to decide if it should break or not.
"""
def __init__(self, *args, **kwargs):
super(UserspaceBreakpoint, self).__init__(*args, **kwargs)
for objfile in gdb.objfiles():
filename = objfile.filename.split("/")[-1]
if not filename.startswith("sunrise-kernel"):
self.proc_name = filename.split("sunrise-")[-1]
break


def stop (self):
cur_proc_name_expr = "(*sunrise_kernel::scheduler::CURRENT_THREAD.0.ptr.pointer).data.process.ptr.pointer.data.name.vec.buf.ptr.pointer"
cur_proc_name = gdb.parse_and_eval(cur_proc_name_expr).string()
if cur_proc_name == self.proc_name:
return True
return False

class BreakUserspaceCommand(gdb.Command):
"""Break only if in the right sunrise executable

Creates a breakpoint that breaks only if we're in the right userspace executable, since all .text are loaded at the same address.

It uses the name found in the kernel current ProcessStruct and compares it with the module we're debugging to decide if it should break or not.

Usage:
break_userspace { args forwarded to break }
"""
def __init__(self):
super(BreakUserspaceCommand, self).__init__(
"break_userspace",
gdb.COMMAND_BREAKPOINTS,
gdb.COMPLETE_LOCATION,
False)

def invoke(self, args, from_tty):
UserspaceBreakpoint(args)

BreakUserspaceCommand()
14 changes: 14 additions & 0 deletions scripts/gdb/gdbinit
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Connect to the qemu stub through tcp.
# This should block until the compilation has ended and qemu has started,
# so it guarantees we are sourcing the up-to-date binaries afterward.
target remote :9090

# Add the kernel and all its symbols.
file isofiles/boot/sunrise-kernel

# Add a userspace process and all its symbols.
# We specify the address at which the kernel loaded it.
add-symbol-file isofiles/boot/sunrise-shell 0x00400000

# Source sunrise scripts.
source scripts/gdb/break_userspace.py