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

show basename in source: split line #1017

Merged
merged 2 commits into from
Nov 28, 2023
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
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
14 changes: 12 additions & 2 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,10 +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) > 20:
fn = f"{fn[:15]}[...]{os.path.splitext(fn)[1]}"
if len(fn) > show_full_path_max:
base = os.path.basename(fn)
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
Loading