Fix game:addSpawnShapesByZone
[ryzomcore.git] / nel / tools / memory / memlog / memlog.cpp
blob8112f6181019910cb87025674e4d00f357f826aa
1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include <nel/misc/types_nl.h>
18 #include <nel/misc/common.h>
19 #include <map>
21 using namespace std;
23 class CLogEntry
25 public:
26 uint32 Start;
27 uint32 End;
28 uint16 Line;
29 std::string Category;
30 std::string Filename;
33 bool readString (string &str, FILE *file)
35 int c;
36 while ((c = fgetc (file)))
38 if (c == EOF)
39 return false;
40 str += c;
42 return true;
45 int main(int argc, char* argv[])
47 if (argc>1)
49 char buffer[512];
50 while (fgets(buffer, 512, stdin))
52 uint32 address;
53 if (strcmp (buffer, "help") == 0)
55 printf ("Commands available:\n");
56 printf ("help | Show this help\n");
57 printf ("address [memoryaddress] | Show history of this address\n");
58 printf ("\n");
59 printf ("memoryaddress must be like this: 8b125df\n");
61 else if (sscanf (buffer, "address %x", &address) == 1)
63 printf ("0x%x history:\n", address);
64 // Read the memory log
65 FILE *file = fopen (argv[1], "rb");
66 if (file)
68 uint32 size;
69 if (fread (&size, sizeof(uint32), 1, file) != 1)
70 break;
72 #ifdef NL_BIG_ENDIAN
73 NLMISC_BSWAP32(size);
74 #endif
76 while (1)
78 uint32 start;
79 if (fread (&start, sizeof(uint32), 1, file) != 1)
80 break;
82 #ifdef NL_BIG_ENDIAN
83 NLMISC_BSWAP32(start);
84 #endif
86 string category;
87 if (!readString (category, file))
88 break;
90 if (start <= address && address < (start+size))
91 printf ("0x%x (%d bytes) %s\n", start, size, category.c_str ());
93 fclose (file);
94 printf ("done\n");
97 else
99 fprintf (stderr, "Can't open the file %s for reading\n", argv[1]);
102 else
104 printf ("Command unknown, try help\n");
108 else
110 printf ("memlog [filename.memlog]\n");
113 return 0;