Skip to content

Commit

Permalink
add control over the widht of source path splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
bartman committed Nov 28, 2023
1 parent 2bc7096 commit e80d01b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
20 changes: 20 additions & 0 deletions docs/commands/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,26 @@ gef➤ gef config context.ignore_registers "$cs $ds $gs"
gef➤ gef config context.show_source_code_variable_values 0
```

* Control how source file path is displayed.

When displaying the source file name, above the source code view, the following
settings can be changed:

```text
gef➤ gef config context.show_full_source_file_name_max_len 30
gef➤ gef config context.show_prefix_source_path_name_len 10
gef➤ gef config context.show_basename_source_file_name_max_len 20
```

In this example, if the file path length is less than or equal to 30 it will be
displayed in its entirety. If however, it's more than 30 characters in length,
it will be truncated.

Truncation first splits the path into the prefix part and file name part. The
`show_prefix_source_path_name_len` controls how many characters of the prefix
path to show, and the `show_basename_source_file_name_max_len` controls how
many characters from the file name to show.

* Show better definitions for call to libc functions.

```text
Expand Down
15 changes: 11 additions & 4 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -7220,6 +7220,9 @@ def __init__(self) -> None:
super().__init__()
self["enable"] = (True, "Enable/disable printing the context when breaking")
self["show_source_code_variable_values"] = (True, "Show extra PC context info in the source code")
self["show_full_source_file_name_max_len"] = (30, "Show full source path name, if less than this value")
self["show_basename_source_file_name_max_len"] = (20, "Show the source basename in full, if less than this value")
self["show_prefix_source_path_name_len"] = (10, "When truncating source path, show this many path prefix characters")
self["show_stack_raw"] = (False, "Show the stack pane as raw hexdump (no dereference)")
self["show_registers_raw"] = (False, "Show the registers pane with raw values (no dereference)")
self["show_opcodes_size"] = (0, "Number of bytes of opcodes to display next to the disassembly")
Expand Down Expand Up @@ -7661,13 +7664,17 @@ def context_source(self) -> None:
bp_locations = [b.location for b in breakpoints if b.location and file_base_name in b.location]
past_lines_color = gef.config["theme.old_context"]

show_full_path_max = self["show_full_source_file_name_max_len"]
show_basename_path_max = self["show_basename_source_file_name_max_len"]
show_prefix_path_len = self["show_prefix_source_path_name_len"]

nb_line = self["nb_lines_code"]
fn = symtab.filename
if len(fn) > 30:
if len(fn) > show_full_path_max:
base = os.path.basename(fn)
if len(base) > 20:
base = f"{base[-10:]}"
fn = f"{fn[:15]}[...]{base}"
if len(base) > show_basename_path_max:
base = base[-show_basename_path_max:]
fn = fn[:15] + "[...]" + base
title = f"source:{fn}+{line_num + 1}"
cur_line_color = gef.config["theme.source_current_line"]
self.context_title(title)
Expand Down

0 comments on commit e80d01b

Please sign in to comment.