1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
4 Copyright (C) 2000 Kh. Naba Kumar Singh
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.
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.
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, MA 02110-1301 USA
37 #include <glib/gi18n.h>
38 #include <libanjuta/anjuta-launcher.h>
39 #include <libanjuta/interfaces/ianjuta-message-manager.h>
40 #include <libanjuta/interfaces/ianjuta-message-view.h>
42 #include "utilities.h"
44 #define ICON_FILE "anjuta-gdb.plugin.png"
45 #define SRCH_CHAR '\\'
48 get_hex_as (const gchar c
)
53 return toupper (c
) - 'A' + 10;
57 get_hex_b (const gchar c1
, const gchar c2
)
59 return get_hex_as (c1
) * 16 + get_hex_as(c2
);
63 gdb_util_get_str_cod (const gchar
*szIn
)
66 g_return_val_if_fail( NULL
!= szIn
, NULL
);
67 szRet
= g_malloc( strlen( szIn
)+2 );
70 gchar
* szDst
= szRet
;
73 if( SRCH_CHAR
== szIn
[0] )
75 if( SRCH_CHAR
== szIn
[1] )
81 *szDst
++ = get_hex_b (szIn
[1], szIn
[2]);
95 gdb_util_parse_error_line (const gchar
* line
, gchar
** filename
, guint
*lineno
)
102 while (line
[i
++] != ':')
104 if (i
>= strlen (line
) || i
>= 512 || line
[i
- 1] == ' ')
109 if (isdigit (line
[i
]))
112 while (isdigit (line
[i
++])) ;
113 dummy
= g_strndup (&line
[j
], i
- j
- 1);
114 *lineno
= strtoul (dummy
, NULL
, 10);
117 dummy
= g_strndup (line
, j
- 1);
118 *filename
= g_strdup (g_strstrip (dummy
));
125 i
= strlen (line
) - 1;
126 while (isspace (line
[i
]) == FALSE
)
137 while (line
[i
++] != ':')
139 if (i
>= strlen (line
) || i
>= 512 || line
[i
- 1] == ' ')
146 if (isdigit (line
[i
]))
149 while (isdigit (line
[i
++])) ;
150 dummy
= g_strndup (&line
[j
], i
- j
- 1);
151 *lineno
= strtoul (dummy
, NULL
, 10);
154 dummy
= g_strndup (&line
[k
], j
- k
- 1);
155 *filename
= g_strdup (g_strstrip (dummy
));
166 gdb_util_remove_white_spaces (const gchar
* text
)
168 guint src_count
, dest_count
, tab_count
;
169 gchar buff
[2048]; /* Let us hope that it does not overflow */
174 for (src_count
= 0; src_count
< strlen (text
); src_count
++)
176 if (text
[src_count
] == '\t')
179 for (j
= 0; j
< tab_count
; j
++)
180 buff
[dest_count
++] = ' ';
182 else if (isspace (text
[src_count
]))
184 buff
[dest_count
++] = ' ';
188 buff
[dest_count
++] = text
[src_count
];
191 buff
[dest_count
] = '\0';
192 return g_strdup (buff
);
196 gdb_util_remove_blank_lines (const GList
* lines
)
202 list
= g_list_copy ((GList
*)lines
);
210 node
= g_list_next (node
);
213 list
= g_list_remove (list
, str
);
216 if (strlen (g_strchomp (str
)) < 1)
217 list
= g_list_remove (list
, str
);
222 /* Excluding the final 0 */
223 gint
gdb_util_calc_string_len( const gchar
*szStr
)
227 return strlen( szStr
)*3 ; /* Leave space for the translated character */
230 gint
gdb_util_calc_gnum_len(void)
232 return 24 ; /* size of a stringfied integer */
235 /* Allocates a struct of pointers */
237 gdb_util_string_parse_separator (const gint nItems
, gchar
*szStrIn
,
240 gchar
**szAllocPtrs
= (char**)g_new( gchar
*, nItems
);
241 if( NULL
!= szAllocPtrs
)
244 gboolean bOK
= TRUE
;
246 for( i
= 0 ; i
< nItems
; i
++ )
249 szp
= strchr( p
, chSep
) ;
253 szp
[0] = '\0' ; /* Parse Operation */
263 g_free( szAllocPtrs
);
271 gdb_util_kill_process (pid_t process_id
, const gchar
* signal
)
277 pid_str
= g_strdup_printf ("%d", process_id
);
281 execlp ("kill", "kill", "-s", signal
, pid_str
, NULL
);
282 g_warning (_("Cannot execute command: \"%s\""), "kill");
287 waitpid (pid
, &status
, 0);
294 /* Debugger message manager management */
297 static const gchar
* MESSAGE_VIEW_TITLE
= N_("Debug");
300 on_gdb_util_mesg_view_destroy(GdbPlugin
* plugin
, gpointer destroyed_view
)
302 plugin
->mesg_view
= NULL
;
306 on_gdb_util_debug_buffer_flushed (IAnjutaMessageView
*view
, const gchar
* line
,
307 AnjutaPlugin
*plugin
)
309 g_return_if_fail (line
!= NULL
);
311 IAnjutaMessageViewType type
= IANJUTA_MESSAGE_VIEW_TYPE_NORMAL
;
312 ianjuta_message_view_append (view
, type
, line
, "", NULL
);
316 on_gdb_util_debug_mesg_clicked (IAnjutaMessageView
* view
, const gchar
* line
,
317 AnjutaPlugin
* plugin
)
319 /* FIXME: Parse the given line */
322 static IAnjutaMessageView
*
323 gdb_util_get_message_view (AnjutaPlugin
*plugin
)
326 IAnjutaMessageView
*message_view
;
327 IAnjutaMessageManager
*message_manager
= NULL
;
328 GdbPlugin
*gdb_plugin
= ANJUTA_PLUGIN_GDB (plugin
);
330 g_return_val_if_fail (plugin
!= NULL
, NULL
);
332 if (gdb_plugin
->mesg_view
)
333 return gdb_plugin
->mesg_view
;
335 /* TODO: error checking */
336 obj
= anjuta_shell_get_object (plugin
->shell
, "IAnjutaMessageManager",
338 message_manager
= IANJUTA_MESSAGE_MANAGER (obj
);
339 message_view
= ianjuta_message_manager_add_view (
340 message_manager
, MESSAGE_VIEW_TITLE
, ICON_FILE
, NULL
);
341 g_object_weak_ref (G_OBJECT (message_view
),
342 (GWeakNotify
)on_gdb_util_mesg_view_destroy
, plugin
);
343 g_signal_connect (G_OBJECT (message_view
), "buffer-flushed",
344 G_CALLBACK (on_gdb_util_debug_buffer_flushed
), plugin
);
345 g_signal_connect (G_OBJECT (message_view
), "message-clicked",
346 G_CALLBACK (on_gdb_util_debug_mesg_clicked
), plugin
);
347 ianjuta_message_manager_set_current_view (message_manager
, message_view
,
349 gdb_plugin
->mesg_view
= message_view
;
355 gdb_util_append_message (AnjutaPlugin
*plugin
, const gchar
* message
)
357 IAnjutaMessageView
*message_view
= NULL
;
359 g_return_if_fail (plugin
!= NULL
);
361 /* TODO: error checking */
362 message_view
= gdb_util_get_message_view (plugin
);
363 ianjuta_message_view_buffer_append (message_view
, message
, NULL
);
367 gdb_util_show_messages (AnjutaPlugin
*plugin
)
370 IAnjutaMessageManager
*message_manager
= NULL
;
371 IAnjutaMessageView
*message_view
= NULL
;
373 /* TODO: error checking */
374 obj
= anjuta_shell_get_object (ANJUTA_PLUGIN (plugin
)->shell
,
375 "IAnjutaMessageManager", NULL
);
376 message_manager
= IANJUTA_MESSAGE_MANAGER (obj
);
377 message_view
= gdb_util_get_message_view (plugin
);
378 ianjuta_message_manager_set_current_view (message_manager
, message_view
,
383 gdb_util_clear_messages (AnjutaPlugin
*plugin
)
385 IAnjutaMessageView
*message_view
= NULL
;
387 g_return_if_fail (plugin
!= NULL
);
389 /* TODO: error checking */
390 message_view
= gdb_util_get_message_view (plugin
);
391 ianjuta_message_view_clear (message_view
, NULL
);