2006-10-30 22:04:34 +01:00
|
|
|
/*
|
|
|
|
* The contents of this file are subject to the Initial
|
|
|
|
* Developer's Public License Version 1.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed AS IS,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing rights
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Vlad Horsun
|
|
|
|
* for the Firebird Open Source RDBMS project.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Vlad Horsun <hvlad@users.sourceforge.net>
|
|
|
|
* and all contributors signed below.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
*/
|
|
|
|
|
2006-11-05 05:01:30 +01:00
|
|
|
#include "firebird.h"
|
2006-10-30 22:04:34 +01:00
|
|
|
#include "../jrd/DebugInterface.h"
|
|
|
|
#include "../jrd/blb_proto.h"
|
|
|
|
|
|
|
|
using namespace Jrd;
|
|
|
|
using namespace Firebird;
|
|
|
|
|
2008-03-06 10:36:45 +01:00
|
|
|
const UCHAR CURRENT_DBG_INFO_VERSION = UCHAR(1);
|
|
|
|
|
2007-01-17 02:19:01 +01:00
|
|
|
void DBG_parse_debug_info(thread_db* tdbb, bid *blob_id, Firebird::DbgInfo& dbgInfo)
|
2006-10-30 22:04:34 +01:00
|
|
|
{
|
2007-12-03 16:46:39 +01:00
|
|
|
Database* dbb = tdbb->getDatabase();
|
2006-10-30 22:04:34 +01:00
|
|
|
blb* blob = BLB_open(tdbb, dbb->dbb_sys_trans, blob_id);
|
|
|
|
const SLONG length = blob->blb_length;
|
|
|
|
Firebird::HalfStaticArray<UCHAR, 128> tmp;
|
|
|
|
|
|
|
|
UCHAR* temp = tmp.getBuffer(length);
|
|
|
|
BLB_get_data(tdbb, blob, temp, length);
|
|
|
|
|
2007-01-20 15:18:18 +01:00
|
|
|
DBG_parse_debug_info(length, temp, dbgInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DBG_parse_debug_info(USHORT length, const UCHAR* data, Firebird::DbgInfo& dbgInfo)
|
|
|
|
{
|
2008-03-06 10:36:45 +01:00
|
|
|
const UCHAR* const end = data + length;
|
2006-10-30 22:04:34 +01:00
|
|
|
bool bad_format = false;
|
|
|
|
|
2007-01-20 15:18:18 +01:00
|
|
|
if ((*data++ != fb_dbg_version) ||
|
2006-10-30 22:04:34 +01:00
|
|
|
(end[-1] != fb_dbg_end) ||
|
2008-03-06 10:36:45 +01:00
|
|
|
(*data++ != CURRENT_DBG_INFO_VERSION))
|
2006-10-30 22:04:34 +01:00
|
|
|
{
|
|
|
|
bad_format = true;
|
|
|
|
}
|
|
|
|
|
2007-01-20 15:18:18 +01:00
|
|
|
while (!bad_format && (data < end))
|
2006-10-30 22:04:34 +01:00
|
|
|
{
|
2007-01-20 15:18:18 +01:00
|
|
|
switch (*data++)
|
2006-10-30 22:04:34 +01:00
|
|
|
{
|
|
|
|
case fb_dbg_map_src2blr:
|
2008-01-16 09:31:31 +01:00
|
|
|
{
|
|
|
|
if (data + 6 > end) {
|
|
|
|
bad_format = true;
|
|
|
|
break;
|
|
|
|
}
|
2006-10-30 22:04:34 +01:00
|
|
|
|
2008-01-16 09:31:31 +01:00
|
|
|
MapBlrToSrcItem i;
|
|
|
|
i.mbs_src_line = *data++;
|
|
|
|
i.mbs_src_line |= *data++ << 8;
|
2006-10-30 22:04:34 +01:00
|
|
|
|
2008-01-16 09:31:31 +01:00
|
|
|
i.mbs_src_col = *data++;
|
|
|
|
i.mbs_src_col |= *data++ << 8;
|
2006-10-30 22:04:34 +01:00
|
|
|
|
2008-01-16 09:31:31 +01:00
|
|
|
i.mbs_offset = *data++;
|
|
|
|
i.mbs_offset |= *data++ << 8;
|
2006-10-30 22:04:34 +01:00
|
|
|
|
2008-01-16 09:31:31 +01:00
|
|
|
dbgInfo.blrToSrc.add(i);
|
|
|
|
}
|
|
|
|
break;
|
2006-10-30 22:04:34 +01:00
|
|
|
|
|
|
|
case fb_dbg_map_varname:
|
2008-01-16 09:31:31 +01:00
|
|
|
{
|
|
|
|
if (data + 3 > end) {
|
|
|
|
bad_format = true;
|
|
|
|
break;
|
|
|
|
}
|
2006-10-30 22:04:34 +01:00
|
|
|
|
2008-01-16 09:31:31 +01:00
|
|
|
// variable number
|
|
|
|
USHORT index = *data++;
|
|
|
|
index |= *data++;
|
2006-10-30 22:04:34 +01:00
|
|
|
|
2008-01-16 09:31:31 +01:00
|
|
|
// variable name string length
|
|
|
|
USHORT length = *data++;
|
2006-10-30 22:04:34 +01:00
|
|
|
|
2008-01-16 09:31:31 +01:00
|
|
|
if (data + length > end) {
|
|
|
|
bad_format = true;
|
|
|
|
break;
|
|
|
|
}
|
2007-01-17 02:19:01 +01:00
|
|
|
|
2008-01-16 09:31:31 +01:00
|
|
|
dbgInfo.varIndexToName.put(index, MetaName((const TEXT*) data, length));
|
2007-01-17 02:19:01 +01:00
|
|
|
|
2008-01-16 09:31:31 +01:00
|
|
|
// variable name string
|
|
|
|
data += length;
|
|
|
|
}
|
|
|
|
break;
|
2007-01-17 02:19:01 +01:00
|
|
|
|
|
|
|
case fb_dbg_map_argument:
|
2008-01-16 09:31:31 +01:00
|
|
|
{
|
|
|
|
if (data + 4 > end) {
|
|
|
|
bad_format = true;
|
|
|
|
break;
|
|
|
|
}
|
2007-01-17 02:19:01 +01:00
|
|
|
|
2008-01-16 09:31:31 +01:00
|
|
|
ArgumentInfo info;
|
2007-01-17 02:19:01 +01:00
|
|
|
|
2008-01-16 09:31:31 +01:00
|
|
|
// argument type
|
|
|
|
info.type = *data++;
|
2007-01-17 02:19:01 +01:00
|
|
|
|
2008-01-16 09:31:31 +01:00
|
|
|
// argument number
|
|
|
|
info.index = *data++;
|
|
|
|
info.index |= *data++;
|
2007-01-17 02:19:01 +01:00
|
|
|
|
2008-01-16 09:31:31 +01:00
|
|
|
// argument name string length
|
|
|
|
USHORT length = *data++;
|
2007-01-17 02:19:01 +01:00
|
|
|
|
2008-01-16 09:31:31 +01:00
|
|
|
if (data + length > end) {
|
|
|
|
bad_format = true;
|
|
|
|
break;
|
|
|
|
}
|
2007-01-17 02:19:01 +01:00
|
|
|
|
2008-01-16 09:31:31 +01:00
|
|
|
dbgInfo.argInfoToName.put(info, MetaName((const TEXT*) data, length));
|
2007-01-17 02:19:01 +01:00
|
|
|
|
2008-01-16 09:31:31 +01:00
|
|
|
// variable name string
|
|
|
|
data += length;
|
|
|
|
}
|
|
|
|
break;
|
2006-10-30 22:04:34 +01:00
|
|
|
|
|
|
|
case fb_dbg_end:
|
2007-01-20 15:18:18 +01:00
|
|
|
if (data != end)
|
2006-10-30 22:04:34 +01:00
|
|
|
bad_format = true;
|
2008-01-16 09:31:31 +01:00
|
|
|
break;
|
2006-10-30 22:04:34 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
bad_format = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-06 10:36:45 +01:00
|
|
|
if (bad_format || data != end)
|
2006-10-30 22:04:34 +01:00
|
|
|
{
|
2007-01-20 15:18:18 +01:00
|
|
|
dbgInfo.clear();
|
2008-06-26 11:47:59 +02:00
|
|
|
ERR_post_warning(isc_bad_debug_format, isc_arg_end);
|
2006-10-30 22:04:34 +01:00
|
|
|
}
|
|
|
|
}
|