Skip to content

Commit 74a18d9

Browse files
committed
Track names of FOR ... AS CURSOR <name>.
1 parent f6188b9 commit 74a18d9

10 files changed

Lines changed: 104 additions & 33 deletions

File tree

src/dsql/BlrDebugWriter.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void BlrDebugWriter::putDebugArgument(UCHAR type, USHORT number, const TEXT* nam
103103
debugData.add(reinterpret_cast<const UCHAR*>(name), len);
104104
}
105105

106-
void BlrDebugWriter::putDebugCursor(USHORT number, const MetaName& name)
106+
void BlrDebugWriter::putDebugDeclaredCursor(USHORT number, const MetaName& name)
107107
{
108108
if (debugData.isEmpty())
109109
return;
@@ -119,6 +119,21 @@ void BlrDebugWriter::putDebugCursor(USHORT number, const MetaName& name)
119119
debugData.add(reinterpret_cast<const UCHAR*>(name.c_str()), len);
120120
}
121121

122+
void BlrDebugWriter::putDebugForCursor(const MetaName& name)
123+
{
124+
if (debugData.isEmpty())
125+
return;
126+
127+
debugData.add(fb_dbg_map_for_curname);
128+
129+
putBlrOffset();
130+
131+
USHORT len = MIN(name.length(), MAX_UCHAR);
132+
debugData.add(len);
133+
134+
debugData.add(reinterpret_cast<const UCHAR*>(name.c_str()), len);
135+
}
136+
122137
void BlrDebugWriter::putDebugSubFunction(DeclareSubFuncNode* subFuncNode)
123138
{
124139
if (debugData.isEmpty())

src/dsql/BlrDebugWriter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ class BlrDebugWriter : public Firebird::BlrWriter
4747
void putDebugSrcInfo(ULONG, ULONG);
4848
void putDebugVariable(USHORT, const MetaName&);
4949
void putDebugArgument(UCHAR, USHORT, const TEXT*);
50-
void putDebugCursor(USHORT, const MetaName&);
50+
void putDebugDeclaredCursor(USHORT, const MetaName&);
51+
void putDebugForCursor(const MetaName&);
5152
void putDebugSubFunction(DeclareSubFuncNode* subFuncNode);
5253
void putDebugSubProcedure(DeclareSubProcNode* subProcNode);
5354

src/dsql/StmtNodes.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ DeclareCursorNode* DeclareCursorNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
12441244
cursorNumber = dsqlScratch->cursorNumber++;
12451245
dsqlScratch->cursors.push(this);
12461246

1247-
dsqlScratch->putDebugCursor(cursorNumber, dsqlName);
1247+
dsqlScratch->putDebugDeclaredCursor(cursorNumber, dsqlName);
12481248

12491249
++dsqlScratch->scopeLevel;
12501250

@@ -1303,7 +1303,7 @@ DeclareCursorNode* DeclareCursorNode::pass2(thread_db* tdbb, CompilerScratch* cs
13031303
ExprNode::doPass2(tdbb, csb, refs.getAddress());
13041304

13051305
MetaName cursorName;
1306-
csb->csb_dbg_info->curIndexToName.get(cursorNumber, cursorName);
1306+
csb->csb_dbg_info->declaredCursorIndexToName.get(cursorNumber, cursorName);
13071307

13081308
// Finish up processing of record selection expressions.
13091309

@@ -4881,6 +4881,9 @@ DmlNode* ForNode::parse(thread_db* tdbb, MemoryPool& pool, CompilerScratch* csb,
48814881
{
48824882
ForNode* node = FB_NEW_POOL(pool) ForNode(pool);
48834883

4884+
if (auto cursorName = csb->csb_dbg_info->forCursorOffsetToName.get(csb->csb_blr_reader.getOffset() - 1))
4885+
csb->csb_forCursorNames.put(node, *cursorName);
4886+
48844887
if (csb->csb_blr_reader.peekByte() == blr_marks)
48854888
node->marks |= PAR_marks(csb);
48864889

@@ -4929,9 +4932,6 @@ ForNode* ForNode::dsqlPass(DsqlCompilerScratch* dsqlScratch)
49294932
dsqlCursor->rse = node->rse;
49304933
dsqlCursor->cursorNumber = dsqlScratch->cursorNumber++;
49314934
dsqlScratch->cursors.push(dsqlCursor);
4932-
4933-
// ASF: We cannot write this cursor name in debug info, as dsqlScratch->cursorNumber is
4934-
// decremented below. But for now we don't need it.
49354935
}
49364936
else
49374937
node->rse = dsqlSelect->dsqlPass(dsqlScratch)->dsqlRse;
@@ -5001,6 +5001,9 @@ void ForNode::genBlr(DsqlCompilerScratch* dsqlScratch)
50015001

50025002
// Generate FOR loop
50035003

5004+
if (dsqlCursor)
5005+
dsqlScratch->putDebugForCursor(dsqlCursor->dsqlName);
5006+
50045007
dsqlScratch->appendUChar(blr_for);
50055008

50065009
if (marks)
@@ -5069,11 +5072,11 @@ StmtNode* ForNode::pass2(thread_db* tdbb, CompilerScratch* csb)
50695072

50705073
RecordSource* const rsb = CMP_post_rse(tdbb, csb, rse.getObject());
50715074

5075+
MetaName cursorName;
5076+
csb->csb_forCursorNames.get(this, cursorName);
5077+
50725078
cursor = FB_NEW_POOL(*tdbb->getDefaultPool())
5073-
Cursor(csb, rsb, rse, !(marks & MARK_AVOID_COUNTERS), line, column);
5074-
// ASF: We cannot define the name of the cursor here, but this is not a problem,
5075-
// as implicit cursors are always positioned in a valid record, and the name is
5076-
// only used to raise isc_cursor_not_positioned.
5079+
Cursor(csb, rsb, rse, !(marks & MARK_AVOID_COUNTERS), line, column, cursorName);
50775080

50785081
csb->csb_fors.add(cursor);
50795082

src/include/firebird/impl/consts_pub.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,8 @@
778778
#define fb_dbg_map_argument 4
779779
#define fb_dbg_subproc 5
780780
#define fb_dbg_subfunc 6
781-
#define fb_dbg_map_curname 7
781+
#define fb_dbg_map_curname 7 /* declared cursor */
782+
#define fb_dbg_map_for_curname 8 /* FOR cursor */
782783
//// TODO: LocalTable name.
783784

784785
// sub code for fb_dbg_map_argument

src/include/gen/Firebird.pas

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4329,6 +4329,7 @@ IProfilerStatsImpl = class(IProfilerStats)
43294329
fb_dbg_subproc = byte(5);
43304330
fb_dbg_subfunc = byte(6);
43314331
fb_dbg_map_curname = byte(7);
4332+
fb_dbg_map_for_curname = byte(8);
43324333
fb_dbg_arg_input = byte(0);
43334334
fb_dbg_arg_output = byte(1);
43344335
isc_facility = 20;

src/jrd/DebugInterface.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,44 @@ void DBG_parse_debug_info(ULONG length, const UCHAR* data, DbgInfo& dbgInfo)
135135
if (code == fb_dbg_map_varname)
136136
dbgInfo.varIndexToName.put(index, MetaName((const TEXT*) data, length));
137137
else
138-
dbgInfo.curIndexToName.put(index, MetaName((const TEXT*) data, length));
138+
dbgInfo.declaredCursorIndexToName.put(index, MetaName((const TEXT*) data, length));
139139

140140
// variable/cursor name string
141141
data += length;
142142
}
143143
break;
144144

145+
case fb_dbg_map_for_curname:
146+
{
147+
if (data + 5 > end)
148+
{
149+
bad_format = true;
150+
break;
151+
}
152+
153+
// fb_dbg_map_for_curname do not exist in DBG_INFO_VERSION_1,
154+
// so always use DBG_INFO_VERSION_2 format.
155+
ULONG offset = *data++;
156+
offset |= *data++ << 8;
157+
offset |= *data++ << 16;
158+
offset |= *data++ << 24;
159+
160+
// variable/cursor name string length
161+
USHORT length = *data++;
162+
163+
if (data + length > end)
164+
{
165+
bad_format = true;
166+
break;
167+
}
168+
169+
dbgInfo.forCursorOffsetToName.put(offset, MetaName((const TEXT*) data, length));
170+
171+
// cursor name string
172+
data += length;
173+
}
174+
break;
175+
145176
case fb_dbg_map_argument:
146177
{
147178
if (data + 4 > end)

src/jrd/DebugInterface.h

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ typedef Firebird::SortedArray<
5858
ULONG,
5959
MapBlrToSrcItem> MapBlrToSrc;
6060

61-
typedef GenericMap<Pair<Right<USHORT, Jrd::MetaName> > > MapVarIndexToName;
62-
6361
struct ArgumentInfo
6462
{
6563
ArgumentInfo(UCHAR aType, USHORT aIndex)
@@ -86,16 +84,15 @@ struct ArgumentInfo
8684
}
8785
};
8886

89-
typedef GenericMap<Pair<Right<ArgumentInfo, Jrd::MetaName> > > MapArgumentInfoToName;
90-
9187
struct DbgInfo : public PermanentStorage
9288
{
9389
explicit DbgInfo(MemoryPool& p)
9490
: PermanentStorage(p),
9591
blrToSrc(p),
9692
varIndexToName(p),
9793
argInfoToName(p),
98-
curIndexToName(p),
94+
declaredCursorIndexToName(p),
95+
forCursorOffsetToName(p),
9996
subFuncs(p),
10097
subProcs(p)
10198
{
@@ -111,10 +108,11 @@ struct DbgInfo : public PermanentStorage
111108
blrToSrc.clear();
112109
varIndexToName.clear();
113110
argInfoToName.clear();
114-
curIndexToName.clear();
111+
declaredCursorIndexToName.clear();
112+
forCursorOffsetToName.clear();
115113

116114
{ // scope
117-
GenericMap<Pair<Left<Jrd::MetaName, DbgInfo*> > >::Accessor accessor(&subFuncs);
115+
LeftPooledMap<Jrd::MetaName, DbgInfo*>::Accessor accessor(&subFuncs);
118116

119117
for (bool found = accessor.getFirst(); found; found = accessor.getNext())
120118
delete accessor.current()->second;
@@ -123,7 +121,7 @@ struct DbgInfo : public PermanentStorage
123121
}
124122

125123
{ // scope
126-
GenericMap<Pair<Left<Jrd::MetaName, DbgInfo*> > >::Accessor accessor(&subProcs);
124+
LeftPooledMap<Jrd::MetaName, DbgInfo*>::Accessor accessor(&subProcs);
127125

128126
for (bool found = accessor.getFirst(); found; found = accessor.getNext())
129127
delete accessor.current()->second;
@@ -133,11 +131,12 @@ struct DbgInfo : public PermanentStorage
133131
}
134132

135133
MapBlrToSrc blrToSrc; // mapping between blr offsets and source text position
136-
MapVarIndexToName varIndexToName; // mapping between variable index and name
137-
MapArgumentInfoToName argInfoToName; // mapping between argument info (type, index) and name
138-
MapVarIndexToName curIndexToName; // mapping between cursor index and name
139-
GenericMap<Pair<Left<Jrd::MetaName, DbgInfo*> > > subFuncs; // sub functions
140-
GenericMap<Pair<Left<Jrd::MetaName, DbgInfo*> > > subProcs; // sub procedures
134+
RightPooledMap<USHORT, Jrd::MetaName> varIndexToName; // mapping between variable index and name
135+
RightPooledMap<ArgumentInfo, Jrd::MetaName> argInfoToName; // mapping between argument info (type, index) and name
136+
RightPooledMap<USHORT, Jrd::MetaName> declaredCursorIndexToName; // mapping between declared cursor index and name
137+
RightPooledMap<ULONG, Jrd::MetaName> forCursorOffsetToName; // mapping between for-cursor offset and name
138+
LeftPooledMap<Jrd::MetaName, DbgInfo*> subFuncs; // sub functions
139+
LeftPooledMap<Jrd::MetaName, DbgInfo*> subProcs; // sub procedures
141140
};
142141

143142
} // namespace Firebird

src/jrd/exe.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,7 @@ class CompilerScratch : public pool_alloc<type_csb>
479479
csb_invariants(p),
480480
csb_current_nodes(p),
481481
csb_current_for_nodes(p),
482+
csb_forCursorNames(p),
482483
csb_computing_fields(p),
483484
csb_inner_booleans(p),
484485
csb_variables_used_in_subroutines(p),
@@ -558,6 +559,7 @@ class CompilerScratch : public pool_alloc<type_csb>
558559
Firebird::Array<ExprNode*> csb_current_nodes; // RseNode's and other invariant
559560
// candidates within whose scope we are
560561
Firebird::Array<ForNode*> csb_current_for_nodes;
562+
Firebird::RightPooledMap<ForNode*, MetaName> csb_forCursorNames;
561563
Firebird::SortedArray<jrd_fld*> csb_computing_fields; // Computed fields being compiled
562564
Firebird::Array<BoolExprNode*> csb_inner_booleans; // Inner booleans at the current scope
563565
Firebird::SortedArray<USHORT> csb_variables_used_in_subroutines;

src/jrd/filters.cpp

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,8 +1432,8 @@ ISC_STATUS filter_debug_info(USHORT action, BlobControl* control)
14321432

14331433
string str;
14341434

1435-
MapArgumentInfoToName::ConstAccessor args(&dbgInfo.argInfoToName);
1436-
if (args.getFirst())
1435+
if (auto args = dbgInfo.argInfoToName.constAccessor();
1436+
args.getFirst())
14371437
{
14381438
string_put(control, "Parameters:");
14391439
str.printf("%10s %-32s %-6s", "Number", "Name", "Type");
@@ -1453,8 +1453,8 @@ ISC_STATUS filter_debug_info(USHORT action, BlobControl* control)
14531453
string_put(control, "");
14541454
}
14551455

1456-
MapVarIndexToName::ConstAccessor vars(&dbgInfo.varIndexToName);
1457-
if (vars.getFirst())
1456+
if (auto vars = dbgInfo.varIndexToName.constAccessor();
1457+
vars.getFirst())
14581458
{
14591459
string_put(control, "Variables:");
14601460
str.printf("%10s %-32s", "Number", "Name");
@@ -1471,8 +1471,8 @@ ISC_STATUS filter_debug_info(USHORT action, BlobControl* control)
14711471
string_put(control, "");
14721472
}
14731473

1474-
MapVarIndexToName::ConstAccessor cursors(&dbgInfo.curIndexToName);
1475-
if (cursors.getFirst())
1474+
if (auto cursors = dbgInfo.declaredCursorIndexToName.constAccessor();
1475+
cursors.getFirst())
14761476
{
14771477
string_put(control, "Cursors:");
14781478
str.printf("%10s %-32s", "Number", "Name");
@@ -1489,6 +1489,24 @@ ISC_STATUS filter_debug_info(USHORT action, BlobControl* control)
14891489
string_put(control, "");
14901490
}
14911491

1492+
if (auto cursors = dbgInfo.forCursorOffsetToName.constAccessor();
1493+
cursors.getFirst())
1494+
{
1495+
string_put(control, "FOR Cursors:");
1496+
str.printf("%10s %-32s", "Offset", "Name");
1497+
string_put(control, str.c_str());
1498+
str.replace(str.begin(), str.end(), str.length(), '-');
1499+
string_put(control, str.c_str());
1500+
1501+
do
1502+
{
1503+
str.printf("%10d %-32s", cursors.current()->first, cursors.current()->second.c_str());
1504+
string_put(control, str.c_str());
1505+
} while (cursors.getNext());
1506+
1507+
string_put(control, "");
1508+
}
1509+
14921510
string_put(control, "BLR to Source mapping:");
14931511
str.printf("%10s %10s %10s", "BLR offset", "Line", "Column");
14941512
string_put(control, str.c_str());

src/jrd/recsrc/Cursor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ namespace Jrd
111111

112112
public:
113113
Cursor(CompilerScratch* csb, const RecordSource* rsb, const RseNode* rse,
114-
bool updateCounters, ULONG line, ULONG column, const MetaName& name = "");
114+
bool updateCounters, ULONG line, ULONG column, const MetaName& name);
115115

116116
void open(thread_db* tdbb) const override;
117117
void close(thread_db* tdbb) const override;

0 commit comments

Comments
 (0)