[lldb-dev] Would Host be better off as a non-static?

Zachary Turner zturner at google.com
Mon Aug 11 11:27:32 PDT 2014


Currently Host is implemented as a static class with lots of ifdefs to
define different versions of methods depending on the OS and platform.

Has anyone ever thought about turning this into a a singleton that returns
an actual instance of a class?  This would provide a number of advantages,
such as:

1) Cleaner code.  You could use interfaces and inheritance to clearly
define the common behavior of a Host, and allow each particular host to
define its own platform specific functionality in derived implementations.

2) More flexibility for supporting non-trivial platform differences.  As a
quick example, currently launching a new process starts a monitoring
thread, and passes data through type-erased batons and the like.  This
might not necessarily be an appropriate model for all platforms.  Maybe I'd
like to use one thread which I simply re-use for many different things,
only one of which is monitoring processes.

3) Member data.  Say you launch 10 processes.  It would be useful if there
were just handles to all 10 processes sitting in an easily accessible
location (at least for Windows anyway, this would be useful).  If there
were a WindowsHost class, I could just have a list of HANDLE items in my
class.

I'm sure there are many more benefits to doing so.

I'm still going over the class implementation, but I wanted to throw this
out there for discussion.  Let's say I did want to go forward with this
refactor though.  Anything I should keep in mind that isn't totally obvious?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/lldb-dev/attachments/20140811/cf9a654f/attachment.html>


More information about the lldb-dev mailing list