[Lldb-commits] [lldb] [lldb] Add 'FindInMemory()' overload for PostMortemProcess. (PR #102536)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Thu Aug 15 06:17:39 PDT 2024
labath wrote:
Thanks for chiming in Jason. I'm glad this is getting attention, as I think that our memory reading APIs are in need of an overhaul -- and it gives me a chance to share my idea. ;)
I don't think that we need to change all of the APIs to return their memory. Sometimes reading the memory into a caller-provided buffer makes perfect sense. What I would like to do is to regularize all the APIs, and avoid the need to implement the logic of e.g. "reading a c string twice". The approach I'd like is to define a `MemoryReader` interface, which would contain all of the ways one may want to read a memory (as a string, integer, etc..). It would also contain a default implementation of the APIs so that an implementation would only need to implement one or two methods and have everything fall out naturally. Then, anything that wants to support that interface, can just inherit from it and implement the required method. If something wants to provide two different methods for reading the memory (I believe Process supports cached and uncached reads), it can just do two implementations, and provide them via different accessors (e.g. `process->CachedMemory()->ReadInt(addr)` and process->DirectMemory()->ReadInt(addr)`).
Another nice part about this is that if we have some code, which only needs to read memory, then it can take a MemoryReader reference (instead of Process or whatever), and then it can be unit tested by just passing it a mock memory reader.
https://github.com/llvm/llvm-project/pull/102536
More information about the lldb-commits
mailing list