Update copyright to LGPL on all files
[dyninst.git] / testsuite / src / symtab / symtab_comp.C
1 /*
2  * Copyright (c) 1996-2009 Barton P. Miller
3  * 
4  * We provide the Paradyn Parallel Performance Tools (below
5  * described as "Paradyn") on an AS IS basis, and do not warrant its
6  * validity or performance.  We reserve the right to update, modify,
7  * or discontinue this software at any time.  We shall have no
8  * obligation to supply such updates or modifications or any other
9  * form of support to you.
10  * 
11  * By your use of Paradyn, you understand and agree that we (or any
12  * other person or entity with proprietary rights in Paradyn) are
13  * under no obligation to provide either maintenance services,
14  * update services, notices of latent defects, or correction of
15  * defects for Paradyn.
16  * 
17  * This library is free software; you can redistribute it and/or
18  * modify it under the terms of the GNU Lesser General Public
19  * License as published by the Free Software Foundation; either
20  * version 2.1 of the License, or (at your option) any later version.
21  * 
22  * This library is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
25  * Lesser General Public License for more details.
26  * 
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30  */
31
32 #include "symtab_comp.h"
33 #include <stdlib.h>
34
35 using namespace Dyninst;
36 using namespace SymtabAPI;
37
38 SymtabComponent::SymtabComponent()
39 {
40 }
41
42 SymtabComponent::~SymtabComponent()
43 {
44 }
45
46 test_results_t SymtabComponent::program_setup(ParameterDict &params)
47 {
48    return PASSED;
49 }
50
51 test_results_t SymtabComponent::program_teardown(ParameterDict &params)
52 {
53    return PASSED;
54 }
55
56 test_results_t SymtabComponent::group_setup(RunGroup *group, ParameterDict &params)
57 {
58    symtab = NULL;
59         //mutatee_p.setString(group->mutatee);
60         compiler_p.setString(group->compiler);
61 #if defined (cap_serialization_test)
62         const char *ser_env = getenv(SERIALIZE_CONTROL_ENV_VAR);
63         //  allow user to explicitly disable serialization in environment
64         //  check this before we modify any environment vars
65         if (ser_env && !strcmp(ser_env, SERIALIZE_DISABLE))
66         {
67                 logerror( "%s[%d]:  serialization is disabled\n", FILE__, __LINE__);
68         }
69         else
70         {
71                 Symtab *s_open = Symtab::findOpenSymtab(std::string(group->mutatee));
72                 switch (group->useAttach)
73                 {
74                         case DESERIALIZE:
75                                 {
76                                         logerror("%s[%d]:  runmode DESERIALIZE\n", FILE__, __LINE__);
77                                         fflush(NULL);
78                                         //  If we have an open symtab with this name, it will just be returned
79                                         //  when we call openFile.  If it is sourced from a regular parse, 
80                                         // this will not trigger deserialization, so we need to close the
81                                         //  existing open symtab if it was not deserialized.
82                                         if (s_open && !s_open->from_cache())
83                                         {
84                                                 logerror( "%s[%d]:  closing open symtab for %s\n", 
85                                                                 FILE__, __LINE__, group->mutatee);
86                                                 Symtab::closeSymtab(s_open);
87                                                 s_open = Symtab::findOpenSymtab(std::string(group->mutatee));
88                                                 if (s_open)
89                                                 { 
90                                                         logerror( "%s[%d]:  failed to close symtab\n", FILE__, __LINE__);
91                                                         return FAILED;
92                                                 }
93
94                                         }
95                                         else
96                                         {
97                                                 if (s_open) 
98                                                 {
99                                                         fprintf(stderr, "%s[%d]:  symtab %s already deserialized\n", FILE__, __LINE__, group->mutatee);
100                                                         logerror( "%s[%d]:  closing open symtab for %s\n", 
101                                                                         FILE__, __LINE__, group->mutatee);
102                                                         Symtab::closeSymtab(s_open);
103                                                         s_open = Symtab::findOpenSymtab(std::string(group->mutatee));
104                                                         if (s_open)
105                                                         { 
106                                                                 logerror( "%s[%d]:  failed to close symtab\n", FILE__, __LINE__);
107                                                                 return FAILED;
108                                                         }
109                                                 }
110                                                 //symtab = s_open;
111                                         }
112                                         enableSerDes<Symtab>(std::string(group->mutatee), true);
113                                         enforceDeserialize<Symtab>(std::string(group->mutatee), true);
114
115                                         //  verify that we have an existing cache for this mutatee from which to deserialize
116                                 }
117                                 break;
118                         case CREATE:
119                                 logerror( "%s[%d]:  runmode CREATE\n", FILE__, __LINE__);
120                                 enableSerialize<Symtab>(std::string(group->mutatee), true);
121                                 enableDeserialize<Symtab>(std::string(group->mutatee), false);
122                                 enforceDeserialize<Symtab>(std::string(group->mutatee), false);
123
124                                 //  Don't think this can happen, but just to be safe, if we have
125                                 //  a deserialized symtab for this mutatee, close it before we
126                                 //  proceed, otherwise it will be returned for the CREATE tests
127                                         if (s_open && s_open->from_cache())
128                                         {
129                                                 logerror( "%s[%d]:  closing open symtab for %s\n", 
130                                                                 FILE__, __LINE__, group->mutatee);
131                                                 Symtab::closeSymtab(s_open);
132                                                 s_open = Symtab::findOpenSymtab(std::string(group->mutatee));
133                                                 if (s_open)
134                                                 { 
135                                                         logerror( "%s[%d]:  failed to close symtab\n", FILE__, __LINE__);
136                                                         return FAILED;
137                                                 }
138                                         }
139                                         else
140                                                 symtab = s_open;
141                                 //  verify that we have an existing cache for this mutatee from which to deserialize
142                                 break;
143                         default:
144                                 logerror( "%s[%d]:  bad runmode!\n", FILE__, __LINE__);
145                                 return FAILED;
146                 }
147         }
148 #endif
149
150    if (group->mutatee && group->state != SELFSTART)
151    {
152            if (NULL == symtab)
153            {
154                    bool result = Symtab::openFile(symtab, std::string(group->mutatee));
155                    if (!result || !symtab)
156                            return FAILED;
157
158 #if defined (cap_serialization_test)
159                 if  (group->useAttach == CREATE)
160                 {
161                         // manually trigger the parsing of type and line info here
162                         // so that everything gets serialized...  for the deserialize tests     
163                         std::vector<SymtabAPI::Module *> mods;
164                         bool result = symtab->getAllModules(mods);
165                         assert(result);
166                         assert(mods[0]);
167                         std::vector<Statement *> statements;
168                         mods[0]->getStatements(statements);
169                         Type *t = symtab->findType(0xdeadbeef);
170                 }
171 #endif
172            }
173            symtab_ptr.setPtr(symtab);
174    }
175    else
176    {
177       symtab_ptr.setPtr(NULL);
178    }
179
180    params["Symtab"] = &symtab_ptr;
181    params["useAttach"]->setInt(group->useAttach);
182    //params["mutatee"] = &mutatee_p;
183    params["compiler"] = &compiler_p;
184    return PASSED;
185 }
186
187 test_results_t SymtabComponent::group_teardown(RunGroup *group, ParameterDict &params)
188 {
189    symtab = NULL;
190    return PASSED;
191 }
192
193 test_results_t SymtabComponent::test_setup(TestInfo *test, ParameterDict &params)
194 {
195    return PASSED;
196 }
197
198 test_results_t SymtabComponent::test_teardown(TestInfo *test, ParameterDict &params)
199 {
200    return PASSED;
201 }
202
203 test_results_t SymtabMutator::setup(ParameterDict &param)
204 {
205    symtab = (Symtab *) param["Symtab"]->getPtr();
206    useAttach = (int) param["useAttach"]->getInt();
207    //mutatee = std::string((const char *)param["mutatee"]->getString());
208    compiler = std::string((const char *)param["compiler"]->getString());
209    return PASSED;
210 }
211
212 SymtabMutator::SymtabMutator() :
213    symtab(NULL)
214 {
215 }
216
217 SymtabMutator::~SymtabMutator()
218 {
219 }
220
221 std::string SymtabComponent::getLastErrorMsg()
222 {
223    return std::string("");
224 }
225
226 TEST_DLL_EXPORT ComponentTester *componentTesterFactory()
227 {
228    return new SymtabComponent();
229 }