1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
2<html>
3<!-- Copyright (C) 1992-2021 Free Software Foundation, Inc.
4Contributed by Cygnus Support.  Written by Julia Menapace, Jim Kingdon,
5and David MacKenzie.
6
7Permission is granted to copy, distribute and/or modify this document
8under the terms of the GNU Free Documentation License, Version 1.3 or
9any later version published by the Free Software Foundation; with no
10Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
11Texts.  A copy of the license is included in the section entitled "GNU
12Free Documentation License". -->
13<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
14<head>
15<title>STABS: Protections</title>
16
17<meta name="description" content="STABS: Protections">
18<meta name="keywords" content="STABS: Protections">
19<meta name="resource-type" content="document">
20<meta name="distribution" content="global">
21<meta name="Generator" content="makeinfo">
22<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
23<link href="index.html#Top" rel="start" title="Top">
24<link href="Symbol-Types-Index.html#Symbol-Types-Index" rel="index" title="Symbol Types Index">
25<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
26<link href="Cplusplus.html#Cplusplus" rel="up" title="Cplusplus">
27<link href="Method-Modifiers.html#Method-Modifiers" rel="next" title="Method Modifiers">
28<link href="Member-Type-Descriptor.html#Member-Type-Descriptor" rel="previous" title="Member Type Descriptor">
29<style type="text/css">
30<!--
31a.summary-letter {text-decoration: none}
32blockquote.smallquotation {font-size: smaller}
33div.display {margin-left: 3.2em}
34div.example {margin-left: 3.2em}
35div.indentedblock {margin-left: 3.2em}
36div.lisp {margin-left: 3.2em}
37div.smalldisplay {margin-left: 3.2em}
38div.smallexample {margin-left: 3.2em}
39div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
40div.smalllisp {margin-left: 3.2em}
41kbd {font-style:oblique}
42pre.display {font-family: inherit}
43pre.format {font-family: inherit}
44pre.menu-comment {font-family: serif}
45pre.menu-preformatted {font-family: serif}
46pre.smalldisplay {font-family: inherit; font-size: smaller}
47pre.smallexample {font-size: smaller}
48pre.smallformat {font-family: inherit; font-size: smaller}
49pre.smalllisp {font-size: smaller}
50span.nocodebreak {white-space:nowrap}
51span.nolinebreak {white-space:nowrap}
52span.roman {font-family:serif; font-weight:normal}
53span.sansserif {font-family:sans-serif; font-weight:normal}
54ul.no-bullet {list-style: none}
55-->
56</style>
57
58
59</head>
60
61<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
62<a name="Protections"></a>
63<div class="header">
64<p>
65Next: <a href="Method-Modifiers.html#Method-Modifiers" accesskey="n" rel="next">Method Modifiers</a>, Previous: <a href="Member-Type-Descriptor.html#Member-Type-Descriptor" accesskey="p" rel="previous">Member Type Descriptor</a>, Up: <a href="Cplusplus.html#Cplusplus" accesskey="u" rel="up">Cplusplus</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Types-Index.html#Symbol-Types-Index" title="Index" rel="index">Index</a>]</p>
66</div>
67<hr>
68<a name="Protections-1"></a>
69<h3 class="section">8.9 Protections</h3>
70
71<p>In the simple class definition shown above all member data and
72functions were publicly accessible.  The example that follows
73contrasts public, protected and privately accessible fields and shows
74how these protections are encoded in C<tt>++</tt> stabs.
75</p>
76<p>If the character following the &lsquo;<samp><var>field-name</var>:</samp>&rsquo; part of the
77string is &lsquo;<samp>/</samp>&rsquo;, then the next character is the visibility.  &lsquo;<samp>0</samp>&rsquo;
78means private, &lsquo;<samp>1</samp>&rsquo; means protected, and &lsquo;<samp>2</samp>&rsquo; means public.
79Debuggers should ignore visibility characters they do not recognize, and
80assume a reasonable default (such as public) (GDB 4.11 does not, but
81this should be fixed in the next GDB release).  If no visibility is
82specified the field is public.  The visibility &lsquo;<samp>9</samp>&rsquo; means that the
83field has been optimized out and is public (there is no way to specify
84an optimized out field with a private or protected visibility).
85Visibility &lsquo;<samp>9</samp>&rsquo; is not supported by GDB 4.11; this should be fixed
86in the next GDB release.
87</p>
88<p>The following C<tt>++</tt> source:
89</p>
90<div class="example">
91<pre class="example">class vis {
92private:
93        int   priv;
94protected:
95        char  prot;
96public:
97        float pub;
98};
99</pre></div>
100
101<p>generates the following stab:
102</p>
103<div class="example">
104<pre class="example"># <span class="roman">128 is N_LSYM</span>
105.stabs &quot;vis:T19=s12priv:/01,0,32;prot:/12,32,8;pub:12,64,32;;&quot;,128,0,0,0
106</pre></div>
107
108<p>&lsquo;<samp>vis:T19=s12</samp>&rsquo; indicates that type number 19 is a 12 byte structure
109named <code>vis</code> The <code>priv</code> field has public visibility
110(&lsquo;<samp>/0</samp>&rsquo;), type int (&lsquo;<samp>1</samp>&rsquo;), and offset and size &lsquo;<samp>,0,32;</samp>&rsquo;.
111The <code>prot</code> field has protected visibility (&lsquo;<samp>/1</samp>&rsquo;), type char
112(&lsquo;<samp>2</samp>&rsquo;) and offset and size &lsquo;<samp>,32,8;</samp>&rsquo;.  The <code>pub</code> field has
113type float (&lsquo;<samp>12</samp>&rsquo;), and offset and size &lsquo;<samp>,64,32;</samp>&rsquo;.
114</p>
115<p>Protections for member functions are signified by one digit embedded in
116the field part of the stab describing the method.  The digit is 0 if
117private, 1 if protected and 2 if public.  Consider the C<tt>++</tt> class
118definition below:
119</p>
120<div class="example">
121<pre class="example">class all_methods {
122private:
123        int   priv_meth(int in){return in;};
124protected:
125        char  protMeth(char in){return in;};
126public:
127        float pubMeth(float in){return in;};
128};
129</pre></div>
130
131<p>It generates the following stab.  The digit in question is to the left
132of an &lsquo;<samp>A</samp>&rsquo; in each case.  Notice also that in this case two symbol
133descriptors apply to the class name struct tag and struct type.
134</p>
135<div class="display">
136<pre class="display">.stabs &quot;class_name:sym_desc(struct tag&amp;type)type_def(21)=
137        sym_desc(struct)struct_bytes(1)
138        meth_name::type_def(22)=sym_desc(method)returning(int);
139        :args(int);protection(private)modifier(normal)virtual(no);
140        meth_name::type_def(23)=sym_desc(method)returning(char);
141        :args(char);protection(protected)modifier(normal)virtual(no);
142        meth_name::type_def(24)=sym_desc(method)returning(float);
143        :args(float);protection(public)modifier(normal)virtual(no);;&quot;,
144        N_LSYM,NIL,NIL,NIL
145</pre></div>
146
147<div class="smallexample">
148<pre class="smallexample">.stabs &quot;all_methods:Tt21=s1priv_meth::22=##1;:i;0A.;protMeth::23=##2;:c;1A.;
149        pubMeth::24=##12;:f;2A.;;&quot;,128,0,0,0
150</pre></div>
151
152<hr>
153<div class="header">
154<p>
155Next: <a href="Method-Modifiers.html#Method-Modifiers" accesskey="n" rel="next">Method Modifiers</a>, Previous: <a href="Member-Type-Descriptor.html#Member-Type-Descriptor" accesskey="p" rel="previous">Member Type Descriptor</a>, Up: <a href="Cplusplus.html#Cplusplus" accesskey="u" rel="up">Cplusplus</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Types-Index.html#Symbol-Types-Index" title="Index" rel="index">Index</a>]</p>
156</div>
157
158
159
160</body>
161</html>
162