]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - www/SB-api-coding-rules.html
Vendor import of lldb trunk r290819:
[FreeBSD/FreeBSD.git] / www / SB-api-coding-rules.html
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2 <html xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
5 <link href="style.css" rel="stylesheet" type="text/css" />
6 <title>LLDB Tutorial</title>
7 </head>
8
9 <body>
10     <div class="www_title">
11       The SB API Coding Rules
12     </div>
13     
14 <div id="container">
15         <div id="content">
16          <!--#include virtual="sidebar.incl"-->
17                 <div id="middle">
18                         <div class="post">
19                                 <h1 class ="postheader">SB API Coding Rules</h1>
20                                 <div class="postcontent">
21
22
23                                   <p>The SB APIs constitute the stable C++ API that lldb presents to external clients, 
24                                     and which get processed by SWIG to produce the Python bindings to lldb.  As such
25                                     it is important that they not suffer from the binary incompatibilities that C++ is
26                                     so susceptible to.  We've established a few rules to ensure that this happens.
27                                     
28                                   <p>The classes in the SB API's are all called SB&lt;SomeName&gt;, where SomeName is in CamelCase
29                                       starting with an upper case letter.  The method names are all CamelCase with initial
30                                       capital letter as well.
31                                       
32                                       <p>All the SB API classes are non-virtual, single inheritance classes.  They should only include
33                                         SBDefines.h or other SB headers as needed.  There should be no inlined method implementations
34                                         in the header files, they should all be in the implementation files.  And there should be no
35                                         direct ivar access.
36
37                                       <p>You also need to choose the ivars for the class with care, since you can't add or remove ivars
38                                         without breaking binary compatibility.  In some cases, the SB class is a thin wrapper around
39                                         an internal lldb_private object.  In that case, the class can have a single ivar, which is
40                                         either a pointer, shared_ptr or unique_ptr to the object in the lldb_private API.  All the
41                                         lldb_private classes that get used this way are declared as opaque classes in lldb_forward.h,
42                                         which is included in SBDefines.h.  So if you need an SB class to wrap an lldb_private class
43                                         that isn't in lldb_forward.h, add it there rather than making a direct opaque declaration in
44                                         the SB classes .h file.  
45
46                                       <p>If the SB Class needs some state of its own, as well as the backing object, don't include that
47                                         as a direct ivar in the SB Class.  Instead, make an Impl class in the SB's .cpp file, and then
48                                         make the SB object hold a shared or unique pointer to the Impl object.  The theory behind this is
49                                         that if you need more state in the SB object, those needs are likely to change over time, 
50                                         and this way the Impl class can pick up members without changing the size of the object.
51                                         An example of this is the SBValue class.  Please note that you should not put this Impl class
52                                         in the lldb namespace.  Failure to do so leads to leakage of weak-linked symbols in the SBAPI.
53                                         
54                                       <p>In order to fit into the Python API's, we need to be able to default construct all the SB objects.
55                                         Since the ivars of the classes are all pointers of one sort or other, this can easily be done, but
56                                         it means all the methods must be prepared to handle their opaque implementation pointer being
57                                         empty, and doing something reasonable.  We also always have an "IsValid" method on all the SB 
58                                         classes to report whether the object is empty or not.
59
60                                       <p>Another piece of the SB API infrastructure is the Python (or other script interpreter) customization.  
61                                         SWIG allows you to add property access, iterators and documentation to classes, but to do that you have to use
62                                         a Swig interface file in place of the .h file. Those files have a different format than a straight C++ header file.  These 
63                                         files are called SB&lt;ClassName&gt;.i, and live in "scripts/interface".  They are constructed by
64                                         starting with the associated .h file, and adding documentation and the Python decorations, etc.  We
65                                         do this in a decidedly low-tech way, by maintaining the two files in parallel.  That simplifies the
66                                         build process, but it does mean that if you add a method to the C++ API's for an SB class, you have
67                                         to copy the interface to the .i file.
68 </div>
69 </body>
70 </html>