From b5df909cdc61a10d750e2d9cb8ba11f4bdec6609 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 4 Aug 2018 22:54:52 +0800 Subject: proc_macro - Add a hacky way of dumping input to the child process (for debugging) --- src/expand/proc_macro.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/expand/proc_macro.cpp') diff --git a/src/expand/proc_macro.cpp b/src/expand/proc_macro.cpp index 7d953e37..3f26c648 100644 --- a/src/expand/proc_macro.cpp +++ b/src/expand/proc_macro.cpp @@ -161,6 +161,7 @@ struct ProcMacroInv: { Span m_parent_span; const ::HIR::ProcMacro& m_proc_macro_desc; + ::std::ofstream m_dump_file; #ifdef WIN32 HANDLE child_handle; @@ -782,6 +783,11 @@ ProcMacroInv::ProcMacroInv(const Span& sp, const char* executable, const ::HIR:: m_parent_span(sp), m_proc_macro_desc(proc_macro_desc) { + // TODO: Optionally dump the data sent to the client. + if( getenv("MRUSTC_DUMP_PROCMACRO") ) + { + m_dump_file.open( getenv("MRUSTC_DUMP_PROCMACRO"), ::std::ios::out | ::std::ios::binary ); + } #ifdef _WIN32 #else int stdin_pipes[2]; @@ -895,6 +901,8 @@ bool ProcMacroInv::check_good() } void ProcMacroInv::send_u8(uint8_t v) { + if( m_dump_file.is_open() ) + m_dump_file.put(v); #ifdef _WIN32 #else if( write(this->child_stdin, &v, 1) != 1 ) @@ -904,6 +912,9 @@ void ProcMacroInv::send_u8(uint8_t v) void ProcMacroInv::send_bytes(const void* val, size_t size) { this->send_v128u( static_cast(size) ); + + if( m_dump_file.is_open() ) + m_dump_file.write( reinterpret_cast(val), size); #ifdef _WIN32 #else if( write(this->child_stdin, val, size) != static_cast(size) ) -- cgit v1.2.3