You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Way to search for string occurence during the lifetime of the program #4047
I'm loving this project so much. I'm curious about the possibility of finding a specific string value (or byte sequence in general) that might've occurred and got dropped at some point during the execution of the program. This would be a really helpful feature for debugging, especially in the context of reverse engineering.
Context
I made a dummy Rust code that has a get_user_input() function that prints "Type Something: " and waits for user input, and a main() function that calls get_user_input() inside an infinite loop as shown here:
use std::io::{self,Write};fnget_user_input(){print!("Type something: ");
std::io::stdout().flush().expect("Failed to flush");letmut input = String::new();
io::stdin().read_line(&mut input).expect("Failed to read line");println!("{}", input);}fnmain(){// Print function addresse at runtimelet addr = get_user_input as*const();println!("Input function location: {:p}", addr);loop{get_user_input();}}
Rust automatically drops the input variable once the get_user_input() function goes out of scope. The string value itself stays in memory, I was able to verify that using PINCE (a Cheat Engine alternative in Linux). But AFAIU, rr doesn't keep track of unallocated memory because it's unnecessary to reproduce the deterministic outcome of the program. So, in order to find that string in the replay and do a bunch of crazy RE stuff like seeing where it originally came from, I would need to position myself in the right time frame.
gdb has a find command to search memory which works under rr.
gdb's find searches memory in the current breakpoint state, is it possible to search memory in the entire history of the program's execution under rr? That would be a neat feature.
In theory that could be done. You could track which memory locations change from moment to moment, and rerun the search to check just the changed memory locations. That would be extremely expensive to run (but could be parallelized). It would also be a lot of work; you'd really need to instrument the program during replay and do a search after every store instruction. So doing it "properly" probably isn't that practical in terms of performance and implementation effort.
I suppose there are optimizations that might help. For example you could build a mask that records, for each possible byte value, whether that value occurs in the string. Whenever there's a store, if the stored byte(s) are not in the string you don't need to search again. And you hope the search string doesn't contain a zero byte...
In practice I think you'll be much better off setting breakpoints at points of interest and then running gdb's find command a lot. If you want that to be faster it could be parallelized inside rr. That's a much more practical improvement.
Activity
rocallahan commentedon Feb 7, 2026
rr reproduces the exact memory and register states of the program, including "unallocated" memory. It's just memory.
gdb has a
findcommand to search memory which works under rr.dtomper commentedon Feb 7, 2026
gdb's
findsearches memory in the current breakpoint state, is it possible to search memory in the entire history of the program's execution under rr? That would be a neat feature.rocallahan commentedon Feb 7, 2026
In theory that could be done. You could track which memory locations change from moment to moment, and rerun the search to check just the changed memory locations. That would be extremely expensive to run (but could be parallelized). It would also be a lot of work; you'd really need to instrument the program during replay and do a search after every store instruction. So doing it "properly" probably isn't that practical in terms of performance and implementation effort.
I suppose there are optimizations that might help. For example you could build a mask that records, for each possible byte value, whether that value occurs in the string. Whenever there's a store, if the stored byte(s) are not in the string you don't need to search again. And you hope the search string doesn't contain a zero byte...
rocallahan commentedon Feb 7, 2026
In practice I think you'll be much better off setting breakpoints at points of interest and then running gdb's
findcommand a lot. If you want that to be faster it could be parallelized inside rr. That's a much more practical improvement.