[Erlang26]怎么通过beam文件得到所有的record或源代码?
1 > c(load,[debug_info]).
{ok,load}
2> beam_lib:chunks(code:which(load),[compile_info]).
{ok,{load,[{compile_info,[{options,[debug_info]},
{version,"5.0.2"},
{time,{2014,11,10,15,19,43}},
{source,"c:/Users/admin/Documents/GitHub/ErlMixCode/src/load/load.erl"}]}]}}
-module(beamI).
%% API
-export([record_attrs/1,beam_to_source/1]).
%%得到record信息[{RecName1,[Filed11,Filed12]},{RecName2,[Filed21,Filed22]}]
record_attrs(Beam) ->
{ok,{_Mod,[{abstract_code,{_Version,Forms}},{"CInf",_CB}]}} =
beam_lib:chunks(code:which(Beam), [abstract_code,"CInf"]),
[join_name_field(D) || {attribute,_,record,D} <- Forms].
%%得到源代码Beam.erl内容:
beam_to_source(Beam) ->
{ok,{_,[{abstract_code,{_,AC}}]}} = beam_lib:chunks(code:which(Beam),[abstract_code]),
io:fwrite("~s~n", [erl_prettypr:format(erl_syntax:form_list(AC))]). join_name_field({Name, Fs}) -> {Name, [element(3, element(3,F)) || F <- Fs]}.
3> beamI:record_attrs(mnesia).
[{tid,[counter,pid]},
{tidstore,[store,up_stores,level]},
{cstruct,[name,type,ram_copies,disc_copies,disc_only_copies,
load_order,access_mode,majority,index,snmp,local_content,
record_name,attributes,user_properties,frag_properties,
storage_properties,cookie,version]},
{log_header,[log_kind,log_version,mnesia_version,node,now]},
{commit,[node,decision,ram_copies,disc_copies,
disc_only_copies,snmp,schema_ops]},
{decision,[tid,outcome,disc_nodes,ram_nodes]},
{cyclic,[node,oid,op,lock,lucky]},
{mnesia_select,[tab,tid,node,storage,cont,written,spec,type,
orig]}]
4> beamI:beam_to_source(load).
-file("load.erl", 1).
-module(load).
-behaviour(gen_server).
-vsn("1.0").
-export([multi_start/0, multi_start/1, start/0, start/1,
start_link/0, start_link/1]).
-export([stop/0, multi_stop/0]).
.......

[Erlang26]怎么通过beam文件得到所有的record或源代码?的更多相关文章
- [Erlang27]如何监控指定目录下的*.beam文件,如果有改动就更新到指定的节点?
在Erlang In Anger第二章中讲到使用rebar来创建一个Erlang项目(Application或Project) 但美中不足的只是给出了指引,但没有给出详细的步骤. 下面我们就使用reb ...
- Xml日志记录文件最优方案(附源代码)
Xml作为数据存储的一种方式,当数据非常大的时候,我们将碰到很多Xml处理的问题.通常,我们对Xml文件进行编辑的最直接的方式是将xml文件加载到XmlDocument,在内存中来对XmlDocume ...
- Android布局文件的载入过程分析:Activity.setContentView()源代码分析
大家都知道在Activity的onCreate()中调用Activity.setContent()方法能够载入布局文件以设置该Activity的显示界面.本文将从setContentView()的源代 ...
- 上传文件时 重新载入页面以获取源代码 http://*/upload.php
今天做一个处理上传文件的接口时碰到这样一个问题, 用的是element-ui的上传组件,但是上传失败, 抓包一看返回的是 重新载入页面以获取源代码 http://*/upload.php 网上搜了一下 ...
- 【Android Developers Training】 42. 从另一台设备接收文件
注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...
- 【Android Developers Training】 41. 向另一台设备发送文件
注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...
- [Erlang06]在Erlang shell怎么在目录A下编译目录B下的文件,并把生成文件统一放置目录C?
问题描述: 我们想快速测试一个小功能,第一个反应就是打开Erl shell 直接输入,但是当想测试一个复杂的函数时,一般会写成一个*.erl文件,然后在shell下: cd(FileDir). c(F ...
- erlang app 文件
http://hje.iteye.com/blog/1211734 应用的概念¶ 当我们写了实现特定功能的代码之后,我们可能想将代码转成一个 应用 (application),这是可以作为一个单元启动 ...
- Erlang那些事儿第2回之我是模块(module),一文件一模块
前几篇文章会写得比较基础,但是既然要写一系列的文章,还是得从基础开始写.我刚学Erlang碰到最大的问题是,想网上搜索下语法,结果却是寥寥无几,而且介绍得不是很系统,对我了解一些细节是有影响的,正好我 ...
随机推荐
- python + docker, 实现天气数据 从FTP获取以及持久化(三)-- python获取FTP数据
前言 经过前面两个小节的介绍,我们已经完成了MySQL数据库的搭建和数据库操作的事宜. 在本小节中,我们需要完成的任务是:使用python从FTP服务其上面获取文本文件. 搭建测试FTP服务器 LZ的 ...
- git/github基本命令
Git与项目 git的使用,主要包括: 本地仓库的命令 远程仓库的命令 项目需求.页面.模型类的设计,及页面的使用 sudo apt-get install git 安装成功后,运行如下命令 git ...
- C++异常处理基本句法测试
针对C++异常机制,作如下简单测试 代码如下: #include<iostream> using namespace std; int MyDivision(int a, int b) { ...
- Python中的strip()函数的用法
函数:string.strip() Python strip() 方法用于移除字符串头尾指定的字符(默认为空格). 一.函数说明 strip() 语法:str.strip([rm]); 参数说明 rm ...
- 「小程序JAVA实战」小程序视频上传方法的抽象复用(57)
转自:https://idig8.com/2018/09/23/xiaochengxujavashizhanxiaochengxushipinshangchuanfangfadechouxiangfu ...
- window.addEventListener()/window.postMessage(”text“, '*')
1.设置监听 window.addEventListener('message', function (msg) { console.log(msg.data);}) 2.发送 message win ...
- 背景半透明rgba最佳实践
by 一丝 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <tit ...
- sdm 使用阿里云域名申请 Let’s Encrypt 通配符 域名证书
安装acme 进入 套件中心 点击安装 Git Server 之后进入SSh会使用git命令 方法1--------------------------------------- 获取代码 git c ...
- Redis 授权操作
[Redis 授权操作] AUTH password 通过设置配置文件中 requirepass 项的值(使用命令 CONFIG SET requirepass password ),可以使用密码来保 ...
- PL/SQL 程序
set serveroutput on