This repository has been archived by the owner on Jul 4, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
all: viewlinkedlist.so linkedlist | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -f linkedlist viewlinkedlist.so | ||
|
||
linkedlist: linkedlist.cpp | ||
g++ -o linkedlist -Wall -O0 -g linkedlist.cpp | ||
|
||
viewlinkedlist.so: viewlinkedlist.cpp | ||
g++ -o viewlinkedlist.so -shared -fPIC -Wall -O0 -g viewlinkedlist.cpp -I../../src/gdb | ||
|
||
# end of Makefile ... | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <string.h> | ||
#include "linkedlist.h" | ||
|
||
static LinkedList *list = NULL; | ||
|
||
static char *xstrdup(const char *str) | ||
{ | ||
const size_t len = strlen(str); | ||
char *retval = new char[len+1]; | ||
strcpy(retval, str); | ||
return retval; | ||
} | ||
|
||
static void AddToList(const char *first, const char *last, int office) | ||
{ | ||
LinkedList *item = new LinkedList; | ||
item->first = xstrdup(first); | ||
item->last = xstrdup(last); | ||
item->office_number = office; | ||
item->next = list; | ||
list = item; | ||
} | ||
|
||
int main(void) | ||
{ | ||
AddToList("Ryan", "Gordon", 4923); | ||
AddToList("Greg", "Read", 227); | ||
AddToList("Linus", "Torvalds", 732); | ||
AddToList("Bill", "Gates", 666); // I kid! I kid! | ||
AddToList("Richard", "Stallman", 1135); | ||
AddToList("Andrew", "Tannenbaum", 9986); | ||
|
||
// now leak all that memory. :) | ||
return 0; | ||
} | ||
|
||
/* end of linkedlist.cpp ... */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef _INCL_LINKEDLIST_H_ | ||
#define _INCL_LINKEDLIST_H_ | ||
|
||
class LinkedList | ||
{ | ||
public: | ||
const char *first; | ||
const char *last; | ||
int office_number; | ||
LinkedList *next; | ||
}; | ||
|
||
#endif | ||
|
||
/* end of linkedlist.h ... */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
#include "linkedlist.h" | ||
#include "gdb-dataplugins.h" | ||
|
||
static void view_linkedlist(const void *ptr, const GDB_dataplugin_funcs *funcs) | ||
{ | ||
LinkedList item; | ||
|
||
while (ptr) | ||
{ | ||
if (funcs->readmem(ptr, &item, sizeof (item)) != 0) | ||
return; | ||
|
||
char *first = (char *) funcs->readstr(item.first, sizeof (char)); | ||
if (first) | ||
{ | ||
char *last = (char *) funcs->readstr(item.last, sizeof (char)); | ||
if (last) | ||
{ | ||
funcs->print("item (%p) { \"%s\", \"%s\", %d }%s\n", | ||
ptr, first, last, item.office_number, | ||
item.next ? "," : ""); | ||
funcs->freemem(last); | ||
} | ||
funcs->freemem(first); | ||
} | ||
|
||
ptr = item.next; | ||
} | ||
} | ||
|
||
void GDB_DATAPLUGIN_ENTRY(const GDB_dataplugin_entry_funcs *funcs) | ||
{ | ||
funcs->register_viewer("LinkedList", view_linkedlist); | ||
} | ||
|
||
/* end of viewlinkedlist.cpp ... */ | ||
|