3 * Toyohashi Open Platform for Embedded Real-Time Systems/
4 * Just Standard Profile Kernel
6 * Copyright (C) 2003 by Embedded and Real-Time Systems Laboratory
7 * Toyohashi Univ. of Technology, JAPAN
9 * ¾åµÃøºî¸¢¼Ô¤Ï¡¤°Ê²¼¤Î (1)¡Á(4) ¤Î¾ò·ï¤«¡¤Free Software Foundation
10 * ¤Ë¤è¤Ã¤Æ¸øɽ¤µ¤ì¤Æ¤¤¤ë GNU General Public License ¤Î Version 2 ¤Ëµ
11 * ½Ò¤µ¤ì¤Æ¤¤¤ë¾ò·ï¤òËþ¤¿¤¹¾ì¹ç¤Ë¸Â¤ê¡¤ËÜ¥½¥Õ¥È¥¦¥§¥¢¡ÊËÜ¥½¥Õ¥È¥¦¥§¥¢
12 * ¤ò²þÊѤ·¤¿¤â¤Î¤ò´Þ¤à¡¥°Ê²¼Æ±¤¸¡Ë¤ò»ÈÍÑ¡¦Ê£À½¡¦²þÊÑ¡¦ºÆÇÛÉۡʰʲ¼¡¤
13 * ÍøÍѤȸƤ֡ˤ¹¤ë¤³¤È¤ò̵½þ¤ÇµöÂú¤¹¤ë¡¥
14 * (1) ËÜ¥½¥Õ¥È¥¦¥§¥¢¤ò¥½¡¼¥¹¥³¡¼¥É¤Î·Á¤ÇÍøÍѤ¹¤ë¾ì¹ç¤Ë¤Ï¡¤¾åµ¤ÎÃøºî
15 * ¸¢É½¼¨¡¤¤³¤ÎÍøÍѾò·ï¤ª¤è¤Ó²¼µ¤Î̵Êݾڵ¬Ä꤬¡¤¤½¤Î¤Þ¤Þ¤Î·Á¤Ç¥½¡¼
16 * ¥¹¥³¡¼¥ÉÃæ¤Ë´Þ¤Þ¤ì¤Æ¤¤¤ë¤³¤È¡¥
17 * (2) ËÜ¥½¥Õ¥È¥¦¥§¥¢¤ò¡¤¥é¥¤¥Ö¥é¥ê·Á¼°¤Ê¤É¡¤Â¾¤Î¥½¥Õ¥È¥¦¥§¥¢³«È¯¤Ë»È
18 * ÍѤǤ¤ë·Á¤ÇºÆÇÛÉÛ¤¹¤ë¾ì¹ç¤Ë¤Ï¡¤ºÆÇÛÉÛ¤Ëȼ¤¦¥É¥¥å¥á¥ó¥È¡ÊÍøÍÑ
19 * ¼Ô¥Þ¥Ë¥å¥¢¥ë¤Ê¤É¡Ë¤Ë¡¤¾åµ¤ÎÃøºî¸¢É½¼¨¡¤¤³¤ÎÍøÍѾò·ï¤ª¤è¤Ó²¼µ
20 * ¤Î̵Êݾڵ¬Äê¤ò·ÇºÜ¤¹¤ë¤³¤È¡¥
21 * (3) ËÜ¥½¥Õ¥È¥¦¥§¥¢¤ò¡¤µ¡´ï¤ËÁȤ߹þ¤à¤Ê¤É¡¤Â¾¤Î¥½¥Õ¥È¥¦¥§¥¢³«È¯¤Ë»È
22 * ÍѤǤ¤Ê¤¤·Á¤ÇºÆÇÛÉÛ¤¹¤ë¾ì¹ç¤Ë¤Ï¡¤¼¡¤Î¤¤¤º¤ì¤«¤Î¾ò·ï¤òËþ¤¿¤¹¤³
24 * (a) ºÆÇÛÉÛ¤Ëȼ¤¦¥É¥¥å¥á¥ó¥È¡ÊÍøÍѼԥޥ˥奢¥ë¤Ê¤É¡Ë¤Ë¡¤¾åµ¤ÎÃø
25 * ºî¸¢É½¼¨¡¤¤³¤ÎÍøÍѾò·ï¤ª¤è¤Ó²¼µ¤Î̵Êݾڵ¬Äê¤ò·ÇºÜ¤¹¤ë¤³¤È¡¥
26 * (b) ºÆÇÛÉۤηÁÂÖ¤ò¡¤Ê̤ËÄê¤á¤ëÊýË¡¤Ë¤è¤Ã¤Æ¡¤TOPPERS¥×¥í¥¸¥§¥¯¥È¤Ë
28 * (4) ËÜ¥½¥Õ¥È¥¦¥§¥¢¤ÎÍøÍѤˤè¤êľÀÜŪ¤Þ¤¿¤Ï´ÖÀÜŪ¤ËÀ¸¤¸¤ë¤¤¤«¤Ê¤ë»
29 * ³²¤«¤é¤â¡¤¾åµÃøºî¸¢¼Ô¤ª¤è¤ÓTOPPERS¥×¥í¥¸¥§¥¯¥È¤òÌÈÀÕ¤¹¤ë¤³¤È¡¥
31 * ËÜ¥½¥Õ¥È¥¦¥§¥¢¤Ï¡¤ÌµÊݾڤÇÄ󶡤µ¤ì¤Æ¤¤¤ë¤â¤Î¤Ç¤¢¤ë¡¥¾åµÃøºî¸¢¼Ô¤ª
32 * ¤è¤ÓTOPPERS¥×¥í¥¸¥§¥¯¥È¤Ï¡¤ËÜ¥½¥Õ¥È¥¦¥§¥¢¤Ë´Ø¤·¤Æ¡¤¤½¤ÎŬÍѲÄǽÀ¤â
33 * ´Þ¤á¤Æ¡¤¤¤¤«¤Ê¤ëÊݾڤâ¹Ô¤ï¤Ê¤¤¡¥¤Þ¤¿¡¤ËÜ¥½¥Õ¥È¥¦¥§¥¢¤ÎÍøÍѤˤè¤êľ
34 * ÀÜŪ¤Þ¤¿¤Ï´ÖÀÜŪ¤ËÀ¸¤¸¤¿¤¤¤«¤Ê¤ë»³²¤Ë´Ø¤·¤Æ¤â¡¤¤½¤ÎÀÕǤ¤òÉé¤ï¤Ê¤¤¡¥
36 * @(#) $Id: fc_binutils.cpp,v 1.21 2004/09/04 15:50:13 honda Exp $
39 #if defined(FILECONTAINER_BINUTILS) || defined(TESTSUITE)
42 #pragma warning(disable:4786) //¥Ç¥Ð¥Ã¥°Ê¸»úÎó¤ò255ʸ»ú¤ËÀÚ¤êµÍ¤á¤¿
45 #include "base/filecontainer.h"
54 #define _isspace(x) isspace(x)
55 #define _isprint(x) isprint(x)
57 #define SIZE_LOADPAGE 65536 //¥Ð¥¤¥Ê¥ê¥Ç¡¼¥¿¤ò³ÊǼ¤¹¤ë¥Ú¡¼¥¸Ã±°Ì
59 #define SIZE_TO_CONFIRM_BINARYFILE 128 //¥Õ¥¡¥¤¥ë¤¬¥Ð¥¤¥Ê¥ê¤ò´Þ¤à¤«¤É¤¦¤«¤ò³Îǧ¤¹¤ë¤Î¤ËÆɤ߽Ф¹¥Ç¡¼¥¿¤ÎŤµ (¥Ð¥Ã¥Õ¥¡¤ò¼è¤ë¤Î¤Ç¤¢¤Þ¤êÂ礤¯¤·¤Ê¤¤¤³¤È)
61 #define MAGIC_SYMBOL "_checker_magic_number"
62 #define MAGIC_NUMBER 0x01234567 //4¥Ð¥¤¥È¤ÎÀ°¿ô
64 #define CMD_GNUNM "nm"
65 #define CMD_GNUOBJCOPY "objcopy"
67 #define MAKE_BASEADDRESS(x) ((x) & ~(SIZE_LOADPAGE-1))
68 #define MAKE_OFFSETADDRESS(x) ((x) & (SIZE_LOADPAGE-1))
74 class FileContainerBinutilsImpl : public FileContainer
77 typedef void (interceptor_func_t)(fstream &, const string &); //ÉÔ°Õ¤Ëˬ¤ì¤¿¥Ð¥¤¥Ê¥ê¥Õ¥¡¥¤¥ë¤Î½±·â¤ËÂбþ¤¹¤ë´Ø¿ô¤Î·¿
81 map<string, address_t> symbol_table;
82 map<address_t, char *> contents;
84 address_t last_address; //¥¥ã¥Ã¥·¥å¤â¤É¤
88 void loadSymbols(fstream & file) throw(Exception);
89 void loadDataContents(fstream & file) throw(Exception);
91 //contents¤Ø1¥Ð¥¤¥È½ñ¤¹þ¤ß
92 void writeByte(address_t address, unsigned int) throw(Exception);
95 void searchSymbolPrefix(void) throw();
96 void searchByteOrder(void) throw();
99 FileContainerBinutilsImpl(void) throw();
100 virtual ~FileContainerBinutilsImpl(void) throw();
102 /* ¥¤¥ó¥¿¥Õ¥§¡¼¥¹Éô */
103 virtual void attachModule(const string & filename) throw(Exception);
104 virtual void loadContents(void * dest, address_t address, size_t size) throw(Exception);
105 virtual address_t getSymbolAddress(const string & symbol) throw(Exception);
106 virtual std::string getArchitecture(void) throw();
108 TESTSUITE_PROTOTYPE(main)
112 FileContainerBinutilsImpl instance_of_FileContainerBinutilsImpl;
116 FileContainerBinutilsImpl::FileContainerBinutilsImpl(void) throw()
117 : symbol_prefix(""), symbol_table(), contents(), last_address(0), last_page(0)
120 /* ¥Ç¥¹¥È¥é¥¯¥¿ : ¥Ç¡¼¥¿¥Ð¥Ã¥Õ¥¡¤Î²òÊü */
121 FileContainerBinutilsImpl::~FileContainerBinutilsImpl(void) throw()
123 map<address_t, char *>::iterator scope;
125 scope = contents.begin();
126 while(scope != contents.end()) {
127 delete [] scope->second;
130 symbol_table.clear();
134 /* ¥Õ¥¡¥¤¥ë̾¤ò¥«¥ó¥Þ¤ÇÆó¤Ä¤Ëʬ¤±¤ë */
135 void splitFilename(const string & src, string & first, string & second) throw(Exception)
138 string::size_type pos;
140 pos = src.find_first_of(',');
141 if(pos != string::npos) {
142 first = src.substr(0, pos);
143 second = src.substr(pos + 1);
146 //¥Õ¥¡¥¤¥ë̾¤¬°ì¤Ä¤·¤«»ØÄꤵ¤ì¤Æ¤¤¤Ê¤¤
152 ExceptionMessage("[FCBI] Empty filename could not be accepted.","[FCBI] ¥Õ¥¡¥¤¥ë̾¤¬¤¢¤ê¤Þ¤»¤ó").throwException();
155 /* ¥Õ¥¡¥¤¥ë¤¬¥Ð¥¤¥Ê¥ê¥Ç¡¼¥¿¤ò»ý¤Ã¤Æ¤¤¤ë¤«¤É¤¦¤«¤òȽÄê */
156 bool hasBinaryContents(fstream & file) throw()
158 assert(file.is_open());
161 char buffer[SIZE_TO_CONFIRM_BINARYFILE];
164 file.read(buffer, SIZE_TO_CONFIRM_BINARYFILE);
165 length = file.gcount();
167 for(streamsize i = 0; i < length; ++ i) {
168 if(buffer[i] < 0 || !(_isprint(buffer[i]) || _isspace(buffer[i]))){
176 file.seekg(0, ios::beg); //ÀèƬ¤ËÌᤷ¤Æ¤ª¤¯
182 /* ¥Æ¥¥¹¥È¥Õ¥¡¥¤¥ë¤ò³«¤¯ (¥Ð¥¤¥Ê¥ê¤À¤Ã¤¿¾ì¹ç¤Ë¤ÏÂнè) */
183 void openTextFile(fstream & file, const string & filename, FileContainerBinutilsImpl::interceptor_func_t * interceptor) throw(Exception)
185 assert(!filename.empty());
186 assert(!file.is_open());
188 file.open(filename.c_str(), ios::in|ios::binary);
189 if(!file.is_open()) {
190 ExceptionMessage("File '%' could not be opened.","¥Õ¥¡¥¤¥ë '%' ¤Ï³«¤±¤Þ¤»¤ó") << filename << throwException;
194 /* ¥Ð¥¤¥Ê¥ê¥Õ¥¡¥¤¥ë¤À¤Ã¤¿¤é... */
195 while(hasBinaryContents(file)) {
198 if(interceptor != 0) {
199 (*interceptor)(file, filename);
200 interceptor = 0; //Âнè¤Ï°ì²ó¤Î¤ß
203 if(!file.is_open()) {
208 /* ¥Õ¥¡¥¤¥ë¤¬³«¤±¤Ê¤«¤Ã¤¿¤éÎã³° */
210 ExceptionMessage("Program failed to convert the binary '%' into suitable style. Please specify a suitable TEXT file.",
211 "¥×¥í¥°¥é¥à¤Ï¥Ð¥¤¥Ê¥ê¥Õ¥¡¥¤¥ë'%'¤ÎÊÑ´¹¤Ë¼ºÇÔ¤·¤Þ¤·¤¿¡£Àµ¤·¤¤¥Æ¥¥¹¥È¥Õ¥¡¥¤¥ë¤ò»ØÄꤷľ¤·¤Æ¤¯¤À¤µ¤¤¡£")
212 << filename << throwException;
215 /* °ì»þŪ¤Ê¥Õ¥¡¥¤¥ë̾¤ÎÀ¸À® */
216 const char * makeTemporaryFilename(void) throw()
218 static char filename[10];
220 sprintf(filename, "cfg%06x", (int)(rand() & 0xffffffl));
226 /* ¥Ð¥¤¥Ê¥ê¤òGNU-NM¤ò»È¤Ã¤ÆÊÑ´¹¤¹¤ë */
227 void interceptWithGnuNM(fstream & file, const string & filename) throw(Exception)
229 assert(!file.is_open());
234 symfile.assign(makeTemporaryFilename());
235 cmdline = string(CMD_GNUNM) + " " + filename + " > " + symfile;
236 VerboseMessage("[EXEC] %\n") << cmdline;
238 system(cmdline.c_str());
240 /* Àµ¤·¤¯³«¤±¤¿¤é¥Õ¥¡¥¤¥ë¤òºï½ü */
241 file.open(symfile.c_str(), ios::in);
243 remove(symfile.c_str());
247 /* ¥Ð¥¤¥Ê¥ê¤òGNU-OBJCOPY¤ò»È¤Ã¤ÆÊÑ´¹¤¹¤ë */
248 void interceptWithGnuObjcopy(fstream & file, const string & filename) throw(Exception)
250 assert(!file.is_open());
255 srecfile.assign(makeTemporaryFilename());
256 cmdline = string(CMD_GNUOBJCOPY) + " -F srec " + filename + " " + srecfile;
257 VerboseMessage("[EXEC] %\n") << cmdline;
259 system(cmdline.c_str());
261 /* Àµ¤·¤¯³«¤±¤¿¤é¥Õ¥¡¥¤¥ë¤òºï½ü */
262 file.open(srecfile.c_str(), ios::in);
264 remove(srecfile.c_str());
268 /* 16¿Ê¤«¤é10¿Ê¤Ø¤ÎÊÑ´¹ (¥Ý¥¤¥ó¥¿°ÜÆ°, Ťµ»ØÄêÉÕ¤) */
269 unsigned int hextodec(const char * & src, size_t length) throw()
271 assert(length <= sizeof(unsigned int) * 2);
273 unsigned int result = 0;
276 while(length-- > 0) {
277 if(*src >= '0' && *src <= '9')
279 else if(*src >= 'A' && *src <='F')
280 digit = *src - 'A' + 10;
281 else if(*src >= 'a' && *src <='f')
282 digit = *src - 'a' + 10;
287 result = (result << 4) | (digit & 0xf);
293 /* NM¤¬½ÐÎϤ·¤¿¹Ô¤ò¥Ñ¡¼¥¹ */
294 bool readGnuNmLine(fstream & file, FileContainer::address_t & address, string & attribute, string & symbolname) throw()
296 assert(file.is_open());
300 string::size_type pos1;
301 string::size_type pos2;
303 /* Ãæ¿È¤ò¶õ¤Ë¤·¤Æ¤ª¤¯ */
305 if(!attribute.empty())
307 if(!symbolname.empty())
310 //¼¡¤Î¹Ô¤ò¼èÆÀ (¶õ¹Ô, ̤ÄêµÁ¥·¥ó¥Ü¥ë¤ÏÆɤßÈô¤Ð¤¹)
315 getline(file, src, '\n');
316 } while(src.empty() || src.at(0) == ' ');
319 pos1 = src.find_first_of(' ');
320 addr = src.substr(0, pos1);
322 pos2 = src.find_first_of(' ', pos1 + 1);
323 attribute = src.substr(pos1 + 1, pos2 - pos1 - 1);
324 symbolname = src.substr(pos2 + 1);
326 //¥¢¥É¥ì¥¹¤Î¥Ñ¡¼¥¹ (Ãí : ¤Ê¤ó¤Ç¤³¤ó¤Ê¤Á¤Þ¤Á¤Þ¤ä¤Ã¤Æ¤ë¤«¤È¤¤¤¦¤È¡¢¥¢¥É¥ì¥¹¤¬32bit¤òĶ¤¨¤ë¥¿¡¼¥²¥Ã¥È¤¬¤¤¤ë¤«¤é)
327 while(!addr.empty()) {
328 size_t length = addr.size();
329 const char * src = addr.c_str();
330 if(length > sizeof(unsigned int) * 2)
331 length = sizeof(unsigned int) * 2;
332 address = (address << (length * 2)) | (hextodec(src, length));
333 addr.erase(0, length);
339 /* ¥·¥ó¥Ü¥ë¤ÎÆɤ߹þ¤ß */
340 void FileContainerBinutilsImpl::loadSymbols(fstream & file) throw(Exception)
342 assert(file.is_open());
348 while(readGnuNmLine(file, address, attribute, symbolname)) {
349 symbol_table.insert(map<string, address_t>::value_type(symbolname, address));
352 VerboseMessage("% symbols loaded\n") << symbol_table.size() << &throwException;
357 /* contents¤Ë1¥Ð¥¤¥È½ñ¤¹þ¤ß */
358 void FileContainerBinutilsImpl::writeByte(address_t address, unsigned int value) throw(Exception)
360 address_t & base = last_address;
361 char * & page = last_page;
363 /* ¥¥ã¥Ã¥·¥å¤â¤É¤¤¬»È¤¨¤Ê¤¤¤Ê¤é¡¢¥Ú¡¼¥¸¤òõ¤¹ */
364 if(MAKE_BASEADDRESS(address) != last_address || last_page == 0) {
365 map<address_t, char *>::iterator scope;
367 base = MAKE_BASEADDRESS(address);
368 scope = contents.find(base);
369 if(scope == contents.end()) {
370 page = new(nothrow) char [SIZE_LOADPAGE];
372 ExceptionMessage("Not enough memory available to store the contents","¶õ¤¥á¥â¥êÉÔ¤Τ¿¤á¡¢¥Ç¡¼¥¿¤Î³ÊǼ¤Ë¼ºÇÔ¤·¤Þ¤·¤¿").throwException();
375 contents.insert(map<address_t,char*>::value_type(base, page));
378 page = scope->second;
381 *(page + (address - base)) = static_cast<char>(value & 0xff);
384 /* ËöÈø¤Î¶õÇòʸ»ú¤òÀÚ¤ê¼è¤ë */
385 void trimString(string & src) throw()
387 string::size_type pos;
389 pos = src.find_last_not_of(" \t\r\n");
390 if(pos != string::npos && pos != src.size())
394 /* ¥â¥È¥í¡¼¥éS¥ì¥³¡¼¥É¤ò°ì¹ÔÆɤ߹þ¤à */
396 The general format of an S-record follows:
397 +-------------------//------------------//-----------------------+
398 | type | count | address | data | checksum |
399 +-------------------//------------------//-----------------------+
401 bool readRecord(fstream & file, string & dest) throw(Exception)
408 /* ¼¡¤Î¹Ô¤òÆɤ߹þ¤à */
410 //getline¤¬ReadFile¤ò¸Æ¤ó¤Ç¥Ö¥í¥Ã¥¯¤¹¤ë¤Î¤Ç¡¢³Î¼Â¤ËEOF¤òÈ¿±þ¤µ¤»¤ë¤¿¤á¤Ë¤³¤¦¤¹¤ë
415 file.putback(static_cast<char>(ch));
417 } while(dest.empty());
423 if(dest[0] != 'S') //¹ÔƬ¤¬'S'¤Ç»Ï¤Þ¤é¤Ê¤¤
424 ExceptionMessage("The file is not a Motorola S-Record file.","¥â¥È¥í¡¼¥éS¥Õ¥©¡¼¥Þ¥Ã¥È¤Ç̵¤¤¹Ô¤¬¸«¤Ä¤«¤ê¤Þ¤·¤¿") << throwException;
426 pos = dest.c_str() + 2;
427 count = hextodec(pos, 2);
428 if(dest.size() != (count + 2)*2)
429 ExceptionMessage("Illegal S-Record found (count unmatched).","ÉÔÀµ¤ÊS¥ì¥³¡¼¥É¤¬¤¢¤ê¤Þ¤¹ (¥µ¥¤¥ºÉÔ°ìÃ×)") << throwException;
432 for(i = 0; i < count; ++ i)
433 sum += hextodec(pos, 2);
435 if((sum & 0xff) != 0xff)
436 ExceptionMessage("Illegal S-Record found (check-sum unmatched).","ÉÔÀµ¤ÊS¥ì¥³¡¼¥É¤¬¤¢¤ê¤Þ¤¹ (¥Á¥§¥Ã¥¯¥µ¥àÉÔ°ìÃ×)") << throwException;
441 /* ¼¡¤Î³«»Ï¥¢¥É¥ì¥¹¤òÆÀ¤ë */
442 FileContainer::address_t parseRecordAddress(const string & src, FileContainer::address_t base) throw()
444 const char * record = src.c_str();
445 FileContainer::address_t result = 0;
448 switch(*(record - 3)) {
450 result = hextodec(record, 4);
453 result = hextodec(record, 6);
456 result = hextodec(record, 8);
468 /* ¥Ç¡¼¥¿Éôʬ¤À¤±¤ò»Ä¤·¤Æ¥Á¥ç¥Ã¥× */
469 void chopRecord(string & src) throw()
471 string::size_type start;
474 case '1': start = 4 + 4; break;
475 case '2': start = 4 + 6; break;
476 case '3': start = 4 + 8; break;
477 default: start = 4; break;
480 //ÀèƬ4¥Ð¥¤¥È + ¥¢¥É¥ì¥¹Éô + ºÇ¸å¤Î¥µ¥à¤ò¼è¤ê½ü¤¯
481 src = src.substr(start, src.size() - start - 2);
484 /* ¥×¥í¥°¥é¥à¥Ç¡¼¥¿¤ÎÆɤ߹þ¤ß */
485 void FileContainerBinutilsImpl::loadDataContents(fstream & file) throw(Exception)
487 assert(file.is_open());
493 while(readRecord(file, line)) {
495 address = parseRecordAddress(line, address);
500 const char * pos = line.c_str();
501 while(*pos != '\x0') {
502 unsigned int data = hextodec(pos, 2);
503 writeByte(address, data);
511 /* ¥·¥ó¥Ü¥ë¥×¥ì¥Õ¥£¥¯¥¹¤Î¼«Æ°È½Äê */
512 void FileContainerBinutilsImpl::searchSymbolPrefix(void) throw()
514 const char * candidate_list[] = {"", "_", NULL};
515 const char ** candidate;
517 for(candidate = candidate_list; *candidate != NULL; ++ candidate) {
518 map<string, address_t>::const_iterator scope;
521 symbol = string(*candidate) + MAGIC_SYMBOL;
522 scope = symbol_table.find(symbol);
524 if(scope != symbol_table.end())
528 if(*candidate != NULL)
529 symbol_prefix.assign(*candidate);
532 /* ¥¨¥ó¥Ç¥£¥¢¥ó¤Î¼«Æ°È½Äê */
533 void FileContainerBinutilsImpl::searchByteOrder(void) throw()
543 address = getSymbolAddress(MAGIC_SYMBOL);
544 loadContents(buffer, address, 4);
546 if(value == MAGIC_NUMBER) {
547 byteorder = HOSTORDER;
550 buffer[0] ^= buffer[3], buffer[3] ^= buffer[0], buffer[0] ^= buffer[3]; // swap(buffer[0], buffer[3])
551 buffer[1] ^= buffer[2], buffer[2] ^= buffer[1], buffer[1] ^= buffer[2]; // swap(buffer[1], buffer[2])
553 if(value == MAGIC_NUMBER)
554 byteorder = HOSTORDER == LITTLE ? BIG : LITTLE;
562 /* ¥â¥¸¥å¡¼¥ë¤Î¥¢¥¿¥Ã¥Á -> ¥·¥ó¥Ü¥ëÆɽФ·, ¥Ç¡¼¥¿³ÊǼ */
563 void FileContainerBinutilsImpl::attachModule(const string & filename) throw(Exception)
566 string symbol_filename;
567 string contents_filename;
569 splitFilename(filename, symbol_filename, contents_filename);
571 openTextFile(file, symbol_filename, interceptWithGnuNM);
574 openTextFile(file, contents_filename, interceptWithGnuObjcopy);
575 loadDataContents(file);
577 searchSymbolPrefix();
581 /* ³ÊǼ¤·¤Æ¤¤¤ëÆâÍƤμèÆÀ */
582 void FileContainerBinutilsImpl::loadContents(void * _dest, address_t address, size_t size) throw(Exception)
584 char * dest = static_cast<char *>(_dest);
587 map<address_t, char *>::const_iterator scope;
589 address_t base = MAKE_BASEADDRESS(address);
590 address_t offset = MAKE_OFFSETADDRESS(address);
591 size_t transfer_size = size;
593 if(transfer_size > SIZE_LOADPAGE - offset)
594 transfer_size = SIZE_LOADPAGE - offset;
596 scope = contents.find(base);
597 if(scope == contents.end())
598 ExceptionMessage("[Internel error] Memory read with unmapped address","[ÆâÉô¥¨¥é¡¼] ¥Þ¥Ã¥×¤µ¤ì¤Æ¤Ê¤¤¥¢¥É¥ì¥¹¤ò»È¤Ã¤Æ¥á¥â¥ê¥ê¡¼¥É¤¬¹Ô¤ï¤ì¤Þ¤·¤¿").throwException();
600 memcpy(dest, scope->second + offset, transfer_size);
602 dest += transfer_size;
603 size -= transfer_size;
607 /* ¥·¥ó¥Ü¥ë¤Î¥¢¥É¥ì¥¹¤Î¼èÆÀ */
608 FileContainer::address_t FileContainerBinutilsImpl::getSymbolAddress(const string & symbol) throw(Exception)
611 map<string, address_t>::const_iterator scope;
613 symbolname = symbol_prefix + symbol;
615 scope = symbol_table.find(symbolname);
616 if(scope == symbol_table.end())
617 ExceptionMessage("Unknown symbol '%'","ÉÔÌÀ¤Ê¥·¥ó¥Ü¥ë̾ '%'") << symbol << throwException;
619 return scope->second;
622 /* ¥¢¡¼¥¥Æ¥¯¥Á¥ã̾¤Î¼èÆÀ */
623 string FileContainerBinutilsImpl::getArchitecture(void) throw()
625 if(byteorder == LITTLE)
626 return "Little endian target (with GNU/Binutils)";
628 return "Big endian target (with GNU/Binutils)";
633 //---------------------------------------------
636 #include "base/coverage_undefs.h"
639 fstream * interceptor_file;
640 string interceptor_filename;
641 void interceptor(fstream & file, const string & filename)
643 CHECKPOINT("interceptor");
644 interceptor_file = &file;
645 interceptor_filename = filename;
647 if(filename.compare("textfile") == 0) {
648 remove(filename.c_str());
649 file.open(filename.c_str(), ios::out);
653 file.open(filename.c_str(), ios::in|ios::binary);
655 else if(filename.compare("binaryfile") == 0) {
656 remove(filename.c_str());
657 file.open(filename.c_str(), ios::out|ios::binary);
661 file.open(filename.c_str(), ios::in|ios::binary);
666 TESTSUITE(main, FileContainerBinutilsImpl)
668 PREDECESSOR("TFileContainer");
670 SingletonBase::ContextChain chain;
671 chain.saveContext<RuntimeObjectTable>();
673 BEGIN_CASE("splitFilename","splitFilename") {
674 BEGIN_CASE("1","¥«¥ó¥Þ¤ÎÁ°¸å¤ÇÀÚ¤ì¤ë") {
675 string first, second;
677 splitFilename("a,b", first, second);
678 TEST_CASE("1","first¤ÎÃæ¿È¤ÏÀµ¤·¤¤", first.compare("a") == 0);
679 TEST_CASE("2","second¤ÎÃæ¿È¤ÏÀµ¤·¤¤", second.compare("b") == 0);
682 BEGIN_CASE("2","¥«¥ó¥Þ¤Î̵¤¤°ú¿ô¤òÍ¿¤¨¤ë¤È¡¢Î¾Êý¤ËƱ¤¸Ãæ¿È¤¬Æþ¤ë") {
683 string first, second;
685 splitFilename("abc", first, second);
686 TEST_CASE("1","first¤ÎÃæ¿È¤ÏÀµ¤·¤¤", first.compare("abc") == 0);
687 TEST_CASE("2","second¤ÎÃæ¿È¤ÏÀµ¤·¤¤", second.compare("abc") == 0);
690 BEGIN_CASE("3","¶õʸ»ú¤òÍ¿¤¨¤ë¤ÈÎã³°") {
692 string first, second;
693 try { splitFilename("", first, second); } catch(Exception &) { result = true; }
699 BEGIN_CASE("hasBinaryContents","hasBinaryContents") {
700 BEGIN_CASE("1","¥Æ¥¥¹¥È¥Õ¥¡¥¤¥ë¤ò¿©¤ï¤»¤ë") {
701 fstream file("test", ios::out);
702 file << "This is a sample text file.";
705 file.open("test",ios::in|ios::binary);
706 TEST_CASE("1","´Ø¿ô¤Ïfalse¤òÊÖ¤¹", !hasBinaryContents(file));
707 TEST_CASE("2","file¤Ïeof¤Ë㤷¤Æ¤¤¤Ê¤¤", !file.eof());
713 BEGIN_CASE("2","¥Ð¥¤¥Ê¥ê¥Ç¡¼¥¿¤ò¿©¤ï¤»¤ë") {
714 fstream file("test", ios::out|ios::binary);
715 file << "This is a sample text file.";
716 file.write("\x0\x1\x2\x3", 4);
719 file.open("test",ios::in|ios::binary);
720 TEST_CASE("1","´Ø¿ô¤Ïtrue¤òÊÖ¤¹", hasBinaryContents(file));
721 TEST_CASE("2","file¤Ïeof¤Ë㤷¤Æ¤¤¤Ê¤¤", !file.eof());
728 BEGIN_CASE("openTextFile","openTextFile") {
729 BEGIN_CASE("1","¥Æ¥¥¹¥È¥Õ¥¡¥¤¥ë¤ò»ØÄꤹ¤ë") {
730 TestSuite::clearCheckpoints();
731 fstream file("test", ios::out);
732 file << "This is a sample text file.";
736 try { openTextFile(file, "test", interceptor); } catch(Exception &) { result = false; }
738 TEST_CASE("1","Îã³°¤Ïµ¯¤¤Ê¤¤", result);
739 TEST_CASE("2","¥Õ¥¡¥¤¥ë¤¬³«¤«¤ì¤Æ¤¤¤ë", file.is_open());
740 TEST_CASE("3","interceptor¤Ï¥³¡¼¥ë¤µ¤ì¤Æ¤¤¤Ê¤¤", !TestSuite::isReached("interceptor"));
743 getline(file, work, '\n');
744 TEST_CASE("4","Æɤ߽Фµ¤ì¤¿ÆâÍƤ¬Àµ¤·¤¤", work.compare("This is a sample text file.") == 0);
750 BEGIN_CASE("2","¥Ð¥¤¥Ê¥ê¥Õ¥¡¥¤¥ë¤ò»ØÄꤹ¤ë (interceptor¤Ï¥Õ¥¡¥¤¥ë¤ò³«¤«¤Ê¤¤)") {
751 TestSuite::clearCheckpoints();
752 fstream file("test", ios::out|ios::binary);
753 file.write("\x1", 1);
757 try { openTextFile(file, "test", interceptor); } catch(Exception &) { result = true; }
759 TEST_CASE("1","Îã³°¤¬µ¯¤¤ë", result);
760 TEST_CASE("2","¥Õ¥¡¥¤¥ë¤¬³«¤«¤ì¤Æ¤¤¤ë", !file.is_open());
761 TEST_CASE("3","interceptor¤¬¥³¡¼¥ë¤µ¤ì¤Æ¤¤¤ë", TestSuite::isReached("interceptor"));
762 TEST_CASE("4","interceptor¤Î°ú¿ô¤¬Àµ¤·¤¤ (file)", interceptor_file == &file);
763 TEST_CASE("5","interceptor¤Î°ú¿ô¤¬Àµ¤·¤¤", interceptor_filename.compare("test") == 0);
769 BEGIN_CASE("3","¸ºß¤·¤Ê¤¤¥Õ¥¡¥¤¥ë¤ò»ØÄꤹ¤ë") {
770 TestSuite::clearCheckpoints();
773 try { openTextFile(file, "___unknown___", interceptor); } catch(Exception &) { result = true; }
775 TEST_CASE("1","Îã³°¤¬µ¯¤¤ë", result);
776 TEST_CASE("2","¥Õ¥¡¥¤¥ë¤¬³«¤«¤ì¤Æ¤¤¤Ê¤¤", !file.is_open());
777 TEST_CASE("3","interceptor¤¬¥³¡¼¥ë¤µ¤ì¤Æ¤¤¤Ê¤¤", !TestSuite::isReached("interceptor"));
780 BEGIN_CASE("4","interceptor¤¬¥Æ¥¥¹¥È¥Õ¥¡¥¤¥ë¤òÀ¸À®¤¹¤ë") {
781 TestSuite::clearCheckpoints();
782 fstream file("textfile", ios::out|ios::binary);
783 file.write("\x1", 1);
787 try { openTextFile(file, "textfile", interceptor); } catch(Exception &) { result = false; }
789 TEST_CASE("1","Îã³°¤Ïµ¯¤¤Ê¤¤", result);
790 TEST_CASE("2","¥Õ¥¡¥¤¥ë¤¬³«¤«¤ì¤Æ¤¤¤ë", file.is_open());
791 TEST_CASE("3","interceptor¤¬¥³¡¼¥ë¤µ¤ì¤Æ¤¤¤ë", TestSuite::isReached("interceptor"));
792 TEST_CASE("4","interceptor¤Î°ú¿ô¤¬Àµ¤·¤¤ (file)", interceptor_file == &file);
793 TEST_CASE("5","interceptor¤Î°ú¿ô¤¬Àµ¤·¤¤", interceptor_filename.compare("textfile") == 0);
796 getline(file, work, '\n');
797 TEST_CASE("4","Æɤ߽Фµ¤ì¤¿ÆâÍƤ¬Àµ¤·¤¤", work.compare("text") == 0);
803 BEGIN_CASE("5","interceptor¤¬¥Ð¥¤¥Ê¥ê¥Õ¥¡¥¤¥ë¤òÀ¸À®¤¹¤ë") {
804 TestSuite::clearCheckpoints();
805 fstream file("binaryfile", ios::out|ios::binary);
806 file.write("\x1", 1);
810 try { openTextFile(file, "binaryfile", interceptor); } catch(Exception &) { result = true; }
812 TEST_CASE("1","Îã³°¤Ïµ¯¤¤ë", result);
813 TEST_CASE("2","¥Õ¥¡¥¤¥ë¤¬³«¤«¤ì¤Æ¤¤¤Ê¤¤", !file.is_open());
814 TEST_CASE("3","interceptor¤¬¥³¡¼¥ë¤µ¤ì¤Æ¤¤¤ë", TestSuite::isReached("interceptor"));
815 TEST_CASE("4","interceptor¤Î°ú¿ô¤¬Àµ¤·¤¤ (file)", interceptor_file == &file);
816 TEST_CASE("5","interceptor¤Î°ú¿ô¤¬Àµ¤·¤¤", interceptor_filename.compare("binaryfile") == 0);
819 remove("binaryfile");
823 BEGIN_CASE("hextodec","hextodec") {
824 const char * letter = "0123456789abcdEFg";
825 const char * work = letter;
827 TEST_CASE("1", "ÀÚ¤ê½Ð¤µ¤ì¤¿Ãͤ¬Àµ¤·¤¤", hextodec(work, 2) == 1);
828 TEST_CASE("2", "work¤¬¿Ê¤ó¤Ç¤¤¤ë", work == letter + 2);
829 TEST_CASE("3", "ÀÚ¤ê½Ð¤µ¤ì¤¿Ãͤ¬Àµ¤·¤¤", hextodec(work, 4) == 0x2345);
830 TEST_CASE("4", "work¤¬¿Ê¤ó¤Ç¤¤¤ë", work == letter + 6);
831 TEST_CASE("5", "ÀÚ¤ê½Ð¤µ¤ì¤¿Ãͤ¬Àµ¤·¤¤", hextodec(work, 8) == 0x6789abcd);
832 TEST_CASE("6", "work¤¬¿Ê¤ó¤Ç¤¤¤ë", work == letter + 14);
833 TEST_CASE("7", "ÀÚ¤ê½Ð¤µ¤ì¤¿Ãͤ¬Àµ¤·¤¤", hextodec(work, 8) == 0xef);
834 TEST_CASE("8", "work¤¬'g'¤Î°ÌÃ֤ǤȤޤë", *work == 'g');
835 TEST_CASE("9", "ÀÚ¤ê½Ð¤µ¤ì¤¿Ãͤ¬Àµ¤·¤¤", hextodec(work, 8) == 0);
836 TEST_CASE("10", "work¤¬'g'¤Î°ÌÃ֤ǤȤޤë", *work == 'g');
839 BEGIN_CASE("readGnuNmLine","readGnuNmLine") {
840 fstream file("test", ios::out);
841 file << "0804aab0 T _kernel_task_initialize\n0805d8a0 B _kernel_tcb_table\n\n0804e560 R _kernel_tinib_table\n U getpid@@GLIBC_2.0\n";
848 file.open("test", ios::in);
849 BEGIN_CASE("1","ÉáÄ̤Υ¨¥ó¥È¥ê¤¬Æɤá¤ë") {
850 TEST_CASE("1","´Ø¿ô¤ÏÀ®¸ù¤¹¤ë", readGnuNmLine(file, address, attribute, symbolname));
851 TEST_CASE("2","address¤ÏÀµ¤·¤¤", address == 0x0804aab0);
852 TEST_CASE("3","attribute¤ÏÀµ¤·¤¤", attribute.compare("T") == 0);
853 TEST_CASE("4","symbolname¤ÏÀµ¤·¤¤", symbolname.compare("_kernel_task_initialize") == 0);
856 BEGIN_CASE("2","ÉáÄ̤Υ¨¥ó¥È¥ê¤¬Æɤá¤ë (2)") {
857 TEST_CASE("1","´Ø¿ô¤ÏÀ®¸ù¤¹¤ë", readGnuNmLine(file, address, attribute, symbolname));
858 TEST_CASE("2","address¤ÏÀµ¤·¤¤", address == 0x0805d8a0);
859 TEST_CASE("3","attribute¤ÏÀµ¤·¤¤", attribute.compare("B") == 0);
860 TEST_CASE("4","symbolname¤ÏÀµ¤·¤¤", symbolname.compare("_kernel_tcb_table") == 0);
863 BEGIN_CASE("3","¶õ¹Ô¤òÆɤßÈô¤Ð¤·¤Æ¼¡¤¬Æɤá¤ë") {
864 TEST_CASE("1","´Ø¿ô¤ÏÀ®¸ù¤¹¤ë", readGnuNmLine(file, address, attribute, symbolname));
865 TEST_CASE("2","address¤ÏÀµ¤·¤¤", address == 0x0804e560);
866 TEST_CASE("3","attribute¤ÏÀµ¤·¤¤", attribute.compare("R") == 0);
867 TEST_CASE("4","symbolname¤ÏÀµ¤·¤¤", symbolname.compare("_kernel_tinib_table") == 0);
870 BEGIN_CASE("4","¥¢¥É¥ì¥¹¤Î̵¤¤¥¨¥ó¥È¥ê¤Ï̵»ë¤¹¤ë") {
871 TEST_CASE("1","´Ø¿ô¤Ï¼ºÇÔ¤¹¤ë", !readGnuNmLine(file, address, attribute, symbolname));
878 BEGIN_CASE("loadSymbols","loadSymbols") {
879 fstream file("test", ios::out);
880 file << "0804aab0 T _kernel_task_initialize\n0805d8a0 B _kernel_tcb_table\n\n0804e560 R _kernel_tinib_table\n U getpid@@GLIBC_2.0\n";
883 file.open("test",ios::in);
885 FileContainerBinutilsImpl fcbi;
886 fcbi.loadSymbols(file);
888 TEST_CASE("1","Æɤ߹þ¤Þ¤ì¤¿¥¨¥ó¥È¥ê¤Î¿ô¤¬Àµ¤·¤¤", fcbi.symbol_table.size() == 3);
889 TEST_CASE("2","¥Õ¥¡¥¤¥ë¤ÏÊĤ¸¤é¤ì¤Æ¤¤¤ë", !file.is_open());
894 BEGIN_CASE("writeByte","writeByte") {
895 FileContainerBinutilsImpl fcbi;
897 BEGIN_CASE("1","¸ºß¤·¤Ê¤¤¥Ú¡¼¥¸¤Ø¤Î½ñ¤¹þ¤ß") {
898 TEST_CASE("0", "[Á°Äó] contents¤ÎÍ×ÁÇ¿ô¤Ï0", fcbi.contents.size() == 0);
899 fcbi.writeByte(0x100, 0);
901 TEST_CASE("1","contents¤ÎÍ×ÁǤ¬Áý¤¨¤Æ¤¤¤ë", fcbi.contents.size() == 1);
903 const char * scope = fcbi.contents.find(MAKE_BASEADDRESS(0x100))->second + MAKE_OFFSETADDRESS(0x100);
904 TEST_CASE("2","½ñ¤¹þ¤Þ¤ì¤Æ¤¤¤ëÆâÍƤ¬Àµ¤·¤¤", *scope == 0);
907 BEGIN_CASE("2","¸ºß¤¹¤ë¥Ú¡¼¥¸¤Ø¤Î½ñ¤¹þ¤ß (Ϣ³¥¢¥¯¥»¥¹)") {
908 fcbi.writeByte(0x100, 0xff);
910 TEST_CASE("1","contents¤ÎÍ×ÁǤ¬Áý¤¨¤Æ¤¤¤Ê¤¤", fcbi.contents.size() == 1);
912 const char * scope = fcbi.contents.find(MAKE_BASEADDRESS(0x100))->second + MAKE_OFFSETADDRESS(0x100);
913 TEST_CASE("2","½ñ¤¹þ¤Þ¤ì¤Æ¤¤¤ëÆâÍƤ¬Àµ¤·¤¤", *scope == 0xff);
916 BEGIN_CASE("3","¿·¤·¤¤¥Ú¡¼¥¸¤Ø¤Î½ñ¤¹þ¤ß") {
917 fcbi.writeByte(0x10000000, 0xff);
919 TEST_CASE("1","contents¤ÎÍ×ÁǤ¬Áý¤¨¤Æ¤¤¤ë", fcbi.contents.size() == 2);
921 const char * scope = fcbi.contents.find(MAKE_BASEADDRESS(0x10000000))->second + MAKE_OFFSETADDRESS(0x10000000);
922 TEST_CASE("2","½ñ¤¹þ¤Þ¤ì¤Æ¤¤¤ëÆâÍƤ¬Àµ¤·¤¤", *scope == 0xff);
925 BEGIN_CASE("4","´û¸¤Î¥Ú¡¼¥¸¤Ø¤Î¥¢¥¯¥»¥¹") {
926 fcbi.writeByte(0x100, 0x0);
928 TEST_CASE("1","contents¤ÎÍ×ÁǤ¬Áý¤¨¤Æ¤¤¤Ê¤¤", fcbi.contents.size() == 2);
930 const char * scope = fcbi.contents.find(MAKE_BASEADDRESS(0x100))->second + MAKE_OFFSETADDRESS(0x100);
931 TEST_CASE("2","½ñ¤¹þ¤Þ¤ì¤Æ¤¤¤ëÆâÍƤ¬Àµ¤·¤¤", *scope == 0x0);
935 BEGIN_CASE("readRecord","readRecord") {
936 fstream file("test",ios::out);
937 file << "S315080480F42F6C69622F6C642D6C696E75782E736F98\n\nS315080480F42F6C69622F6C642D6C696E75782E736F98\nS308080481042E320005\nDUMMY\nS31808048108040000001000000001000000474E550056\nS31008048108040000001000000001000000474E550056\n";
940 file.open("test",ios::in);
941 BEGIN_CASE("1","Àµ¾ï¥±¡¼¥¹") {
944 bool exception = false;
945 try { result = readRecord(file, work); } catch(Exception &) { exception = true; }
946 TEST_CASE("1","Îã³°¤Ïµ¯¤³¤é¤Ê¤¤", !exception);
947 TEST_CASE("2","´Ø¿ô¤Ïtrue¤òÊÖ¤¹", result);
948 TEST_CASE("3","Æɤ߽Фµ¤ì¤¿ÆâÍƤ¬Àµ¤·¤¤", work.compare("S315080480F42F6C69622F6C642D6C696E75782E736F98") == 0);
951 BEGIN_CASE("2","Àµ¾ï¥±¡¼¥¹ (¶õ¹Ô¤ÎÆɤßÈô¤Ð¤·)") {
954 bool exception = false;
955 try { result = readRecord(file, work); } catch(Exception &) { exception = true; }
956 TEST_CASE("1","Îã³°¤Ïµ¯¤³¤é¤Ê¤¤", !exception);
957 TEST_CASE("2","´Ø¿ô¤Ïtrue¤òÊÖ¤¹", result);
958 TEST_CASE("3","Æɤ߽Фµ¤ì¤¿ÆâÍƤ¬Àµ¤·¤¤", work.compare("S315080480F42F6C69622F6C642D6C696E75782E736F98") == 0);
961 BEGIN_CASE("3","¥Á¥§¥Ã¥¯¥µ¥à¤¬¸í¤Ã¤Æ¤¤¤ë¥¨¥ó¥È¥ê") {
964 bool exception = false;
965 try { result = readRecord(file, work); } catch(Exception &) { exception = true; }
966 TEST_CASE("1","Îã³°¤ò¤ª¤³¤¹", exception);
969 BEGIN_CASE("4","ÀèƬ¤¬S¤Ç»Ï¤Þ¤é¤Ê¤¤¥¨¥ó¥È¥ê") {
972 bool exception = false;
973 try { result = readRecord(file, work); } catch(Exception &) { exception = true; }
974 TEST_CASE("1","Îã³°¤ò¤ª¤³¤¹", exception);
977 BEGIN_CASE("5","»ØÄꤵ¤ì¤¿Ä¹¤µ¤è¤ê¤âŤ¤¥¨¥ó¥È¥ê") {
980 bool exception = false;
981 try { result = readRecord(file, work); } catch(Exception &) { exception = true; }
982 TEST_CASE("1","Îã³°¤ò¤ª¤³¤¹", exception);
985 BEGIN_CASE("6","»ØÄꤵ¤ì¤¿Ä¹¤µ¤è¤ê¤âû¤¤¥¨¥ó¥È¥ê") {
988 bool exception = false;
989 try { result = readRecord(file, work); } catch(Exception &) { exception = true; }
990 TEST_CASE("1","Îã³°¤ò¤ª¤³¤¹", exception);
993 BEGIN_CASE("7","¥Õ¥¡¥¤¥ë½ªÃ¼") {
996 bool exception = false;
997 try { result = readRecord(file, work); } catch(Exception &) { exception = true; }
998 TEST_CASE("1","Îã³°¤ò¤ª¤³¤µ¤Ê¤¤", !exception);
999 TEST_CASE("2","´Ø¿ô¤Ïfalse¤òÊÖ¤¹", !result);
1005 BEGIN_CASE("chopRecord","chopRecord") {
1006 BEGIN_CASE("1","S1¥ì¥³¡¼¥É") {
1007 string src("S106080480F42F4A");
1010 TEST_CASE("1","Ãͤ¬Àµ¤·¤¤", src.compare("80F42F") == 0);
1013 BEGIN_CASE("2","S2¥ì¥³¡¼¥É") {
1014 string src("S206080480F42F4A");
1017 TEST_CASE("1","Ãͤ¬Àµ¤·¤¤", src.compare("F42F") == 0);
1020 BEGIN_CASE("3","S3¥ì¥³¡¼¥É") {
1021 string src("S306080480F42F4A");
1024 TEST_CASE("1","Ãͤ¬Àµ¤·¤¤", src.compare("2F") == 0);
1027 BEGIN_CASE("4","S4¥ì¥³¡¼¥É") {
1028 string src("S406080480F42F4A");
1031 TEST_CASE("1","Ãͤ¬Àµ¤·¤¤", src.compare("080480F42F") == 0);
1034 BEGIN_CASE("5","S5¥ì¥³¡¼¥É") {
1035 string src("S506080480F42F4A");
1038 TEST_CASE("1","Ãͤ¬Àµ¤·¤¤", src.compare("080480F42F") == 0);
1043 BEGIN_CASE("loadDataContents/loadContents","loadDataContents/loadContents") {
1044 fstream file("test", ios::out);
1045 file << "S30D000000000123456789ABCDEF32\nS509FEDCBA9876543210BE";
1048 BEGIN_CASE("1","Àµ¾ï¥±¡¼¥¹") {
1049 FileContainerBinutilsImpl fcbi;
1051 file.open("test",ios::in);
1052 bool exception = false;
1053 try { fcbi.loadDataContents(file); } catch(...) { exception = true; }
1055 TEST_CASE("1","Îã³°¤Ïµ¯¤³¤é¤Ê¤¤", !exception);
1056 TEST_CASE("2","¥Ç¡¼¥¿¤¬³ÎÊݤµ¤ì¤Æ¤¤¤ë", fcbi.contents.size() == 1);
1057 TEST_CASE("3","¥Õ¥¡¥¤¥ë¤ÏÊĤ¸¤é¤ì¤Æ¤¤¤ë", !file.is_open());
1058 BEGIN_CASE("4","³ÊǼ¤·¤¿Ãͤ¬Àµ¤·¤¯Æɤá¤ë") {
1061 assert(sizeof(unsigned int) >= 4);
1064 fcbi.loadContents(&i, 0, 4);
1065 TEST_CASE("1","1-4¥Ð¥¤¥ÈÌÜ", i == 0x67452301);
1066 fcbi.loadContents(&i, 4, 4);
1067 TEST_CASE("1","5-8¥Ð¥¤¥ÈÌÜ", i == 0xefcdab89);
1068 fcbi.loadContents(&i, 8, 4);
1069 TEST_CASE("1","9-12¥Ð¥¤¥ÈÌÜ", i == 0x98badcfe);
1070 fcbi.loadContents(&i,12, 4);
1071 TEST_CASE("1","13-16¥Ð¥¤¥ÈÌÜ", i == 0x10325476);
1076 BEGIN_CASE("2","loadContents¤Ç°ìÅ٤˥ڡ¼¥¸¥µ¥¤¥º¤òĶ¤¨¤ëÎ̤òÍ׵᤹¤ë") {
1077 FileContainerBinutilsImpl fcbi;
1080 for(i=0;i<SIZE_LOADPAGE*2;++i)
1081 fcbi.writeByte(i, i);
1083 unsigned char * buffer = new unsigned char [SIZE_LOADPAGE * 2];
1084 fcbi.loadContents(buffer, 0, SIZE_LOADPAGE * 2);
1086 for(i=0;i<SIZE_LOADPAGE*2;++i)
1087 if(*(buffer + i) != (i & 0xff))
1095 BEGIN_CASE("searchSymbolPrefix","searchSymbolPrefix") {
1097 BEGIN_CASE("1","¥×¥ì¥Õ¥£¥¯¥¹¤¬¤Ê¤¤") {
1098 FileContainerBinutilsImpl fcbi;
1099 fcbi.symbol_table.insert(pair<string, address_t>(MAGIC_SYMBOL, 0x100));
1101 fcbi.searchSymbolPrefix();
1102 if(!fcbi.symbol_prefix.empty())
1106 BEGIN_CASE("2","ÊÑ¿ô̾¤Ë\"_\"¤¬¤Ä¤¯¥¿¥¤¥×") {
1107 FileContainerBinutilsImpl fcbi;
1108 fcbi.symbol_table.insert(pair<string, address_t>("_" MAGIC_SYMBOL, 0x100));
1110 fcbi.searchSymbolPrefix();
1111 if(fcbi.symbol_prefix.compare("_") != 0)
1115 BEGIN_CASE("3","\"__\"¤Ë¤ÏÈ¿±þ¤·¤Ê¤¤") {
1116 FileContainerBinutilsImpl fcbi;
1117 fcbi.symbol_table.insert(pair<string, address_t>("__" MAGIC_SYMBOL, 0x100));
1119 fcbi.searchSymbolPrefix();
1120 if(!fcbi.symbol_prefix.empty())
1124 BEGIN_CASE("4","ȯ¸«¤Ç¤¤Ê¤¤¾ì¹ç¡¢Êѹ¹¤·¤Ê¤¤") {
1125 FileContainerBinutilsImpl fcbi;
1126 fcbi.symbol_prefix.assign("test");
1128 fcbi.searchSymbolPrefix();
1129 if(fcbi.symbol_prefix.compare("test") != 0)
1134 BEGIN_CASE("searchByteOrder","searchByteOrder") {
1135 BEGIN_CASE("1","¥Û¥¹¥È¤ÈƱ¤¸¥¨¥ó¥Ç¥£¥¢¥ó") {
1136 FileContainerBinutilsImpl fcbi;
1137 unsigned int value = MAGIC_NUMBER;
1138 fcbi.symbol_table.insert(pair<string, address_t>(MAGIC_SYMBOL, 0x100));
1140 for(int i=0;i<4;i++)
1141 fcbi.writeByte(0x100 + i, *((char *)&value + i));
1143 fcbi.byteorder = UNKNOWN;
1144 fcbi.searchByteOrder();
1146 if(fcbi.byteorder != HOSTORDER)
1150 BEGIN_CASE("2","¥Û¥¹¥È¤È°ã¤¦¥¨¥ó¥Ç¥£¥¢¥ó") {
1151 FileContainerBinutilsImpl fcbi;
1152 unsigned int value = MAGIC_NUMBER;
1153 fcbi.symbol_table.insert(pair<string, address_t>(MAGIC_SYMBOL, 0x100));
1155 for(int i=0;i<4;i++)
1156 fcbi.writeByte(0x100 + i, *((char *)&value + (3 - i)));
1158 fcbi.byteorder = UNKNOWN;
1159 fcbi.searchByteOrder();
1161 if(fcbi.byteorder == HOSTORDER)
1165 BEGIN_CASE("3","¥·¥ó¥Ü¥ë¤¬Ìµ¤¤") {
1166 FileContainerBinutilsImpl fcbi;
1167 unsigned int value = MAGIC_NUMBER;
1169 for(int i=0;i<4;i++)
1170 fcbi.writeByte(0x100 + i, *((char *)&value + (3 - i)));
1172 fcbi.byteorder = UNKNOWN;
1173 fcbi.searchByteOrder();
1175 if(fcbi.byteorder != UNKNOWN)
1179 BEGIN_CASE("4","¥Ç¡¼¥¿¤¬Ìµ¤¤") {
1180 FileContainerBinutilsImpl fcbi;
1181 unsigned int value = MAGIC_NUMBER;
1182 fcbi.symbol_table.insert(pair<string, address_t>(MAGIC_SYMBOL, 0x100));
1184 fcbi.byteorder = UNKNOWN;
1185 fcbi.searchByteOrder();
1187 if(fcbi.byteorder != UNKNOWN)
1192 chain.restoreContext();
1195 #endif /* TESTSUITE */
1197 #endif /* FILECONTAINER_BINUTILS || TESTSUITE */