1 /*
2  *      debug_module.c
3  *
4  *      Copyright 2010 Alexander Petukhov <devel(at)apetukhov.ru>
5  *
6  *      This program is free software; you can redistribute it and/or modify
7  *      it under the terms of the GNU General Public License as published by
8  *      the Free Software Foundation; either version 2 of the License, or
9  *      (at your option) any later version.
10  *
11  *      This program is distributed in the hope that it will be useful,
12  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *      GNU General Public License for more details.
15  *
16  *      You should have received a copy of the GNU General Public License
17  *      along with this program; if not, write to the Free Software
18  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19  *      MA 02110-1301, USA.
20  */
21 
22 /*
23  * 		Contains variable structure constructors and destructors.
24  */
25 
26 #include <stdlib.h>
27 #include <memory.h>
28 
29 #include <gtk/gtk.h>
30 
31 #include "breakpoint.h"
32 #include "debug_module.h"
33 
34 /* creates new variable */
variable_new(const gchar * name,variable_type vt)35 variable *variable_new(const gchar *name, variable_type vt)
36 {
37 	variable *var = g_malloc(sizeof(variable));
38 	var->name = g_string_new(name);
39 	var->internal = g_string_new("");
40 	var->expression = g_string_new("");
41 	var->type = g_string_new("");
42 	var->value = g_string_new("");
43 	var->has_children = var->evaluated = FALSE;
44 	var->vt = vt;
45 
46 	return var;
47 }
48 
49 /* creates new variable with internal name */
variable_new2(const gchar * name,const gchar * internal,variable_type vt)50 variable *variable_new2(const gchar *name, const gchar *internal, variable_type vt)
51 {
52 	variable *var = variable_new(name, vt);
53 	g_string_assign(var->internal, internal);
54 
55 	return var;
56 }
57 
58 /* frees variable */
variable_free(variable * var)59 void variable_free(variable *var)
60 {
61 	g_string_free(var->name, TRUE);
62 	g_string_free(var->internal, TRUE);
63 	g_string_free(var->expression, TRUE);
64 	g_string_free(var->type, TRUE);
65 	g_string_free(var->value, TRUE);
66 	g_free(var);
67 }
68 
69 /* reset all variable fields (except name) */
variable_reset(variable * var)70 void variable_reset(variable *var)
71 {
72 	g_string_assign(var->internal, "");
73 	g_string_assign(var->expression, "");
74 	g_string_assign(var->type, "");
75 	g_string_assign(var->value, "");
76 	var->has_children = var->evaluated = FALSE;
77 }
78 
79 /* creates new frame */
frame_new(void)80 frame* frame_new(void)
81 {
82 	frame *f = g_malloc0(sizeof *f);
83 	f->ref_count = 1;
84 	return f;
85 }
86 
87 /* refs a frame */
frame_ref(frame * f)88 frame* frame_ref(frame* f)
89 {
90 	f->ref_count++;
91 	return f;
92 }
93 
94 /* unrefs a frame */
frame_unref(frame * f)95 void frame_unref(frame* f)
96 {
97 	if (f->ref_count > 1)
98 		f->ref_count--;
99 	else
100 	{
101 		g_free(f->address);
102 		g_free(f->function);
103 		g_free(f->file);
104 		g_free(f);
105 	}
106 }
107